Giter Site home page Giter Site logo

hapi-imagemin-proxy-1's Introduction

hapi-imagemin-proxy

Greenkeeper badge

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

License

MIT

hapi-imagemin-proxy-1's People

Contributors

fhemberger avatar greenkeeperio-bot avatar oronoa avatar snyk-bot avatar greenkeeper[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.