Never Publish Malarkey

npm

Need private packages and team management tools?Check out npm Orgs. »

hapi-imagemin-proxy

2.0.1 • Public • Published

hapi-imagemin-proxy

Image optimization proxy written in Node.js using hapi.

Build Status Current Version

Allows you to resize an image and change image formats. Output is always optimized for the smallest file size.

  • http://localhost:5678/cat.gif,w100 - Resize to a width of 100px
  • http://localhost:5678/cat.gif,w100,h50 - Fit into 100px × 50px (keeping aspect ratio)
  • http://localhost:5678/find-peace.png,jpg - Convert PNG to JPG
  • http://localhost:5678/find-peace.png,w100,h50,jpg - All combined

Usage

Requires GraphicsMagick to be installed (e.g. on Mac OS X via Homebrew: brew install graphicsmagick).

npm install hapi-imagemin-proxy

Afterwards, include hapi-imagemin-proxy as plug-in into your existing Hapi project (a demo server can be found in /example):

const Hapi = require('hapi');
const server = new Hapi.Server();
 
server.register({
    plugin: require('hapi-imagemin-proxy'),
    options: {
        source: '/path/to/images',
        cache: {},
        imageCache: {
            engine: require('catbox-memory'),
            options: {
                expiresIn: 3600000
            }
        },
        plugins: [
            imageminGm.resize(),
            imageminGm.convert(),
            imageminJpegoptim({ progressive: true, max: 75 }),
            imageminPngquant(),
            imageminGifsicle({ optimizationLevel: 3 }),
            imageminSvgo()
        ]
        // ...
    }
}, function (err) {
 
    if (err) {
        return {
            console.error(err);
        }
    }
});

Options

  • source: Location of the images to be served. Can be either a local path or a URL (required).

  • wreck: When source is an URL, these request options are passed to Wreck.

  • cache: Sets Hapi's route.cache options

  • imagecache:

    • engine: Catbox caching engine. Must support binary data, e.g. catbox-s3. Default: require('catbox-memory')
    • options: Engine specific options (optional)
      • maxByteSize: only for catbox-memory, default: 104857600 (100MB)
      • expiresIn: Cache time-to-live in milliseconds, default: 3600000 (one hour)
  • plugins: Array of imagemin optimization plug-ins, defaults:

    imageminJpegoptim({ progressive: true, max: 75 }),
    imageminPngquant(),
    imageminGifsicle({ optimizationLevel: 3 }),
    imageminSvgo()
    

TODO

  • Use cjpeg-dssim for JPG optimization
  • Rewrite using async/await to support hapi@v17.x.x

License

MIT

install

npm i hapi-imagemin-proxy

Downloadsweekly downloads

7

version

2.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability