im-optim
v1.1.1
Published
optimize png, jpeg and svg images
Downloads
5
Readme
Simple image-optimizer for png, jpg, svg
uses:
- mozjpeg
- pngquant+optipng
- svgo
API
var imOptim = require('im-optim');
// imOptim(streamOrBuffer [, contentType]) -> {stream:optimizedStream, size}
// imOptim.pngOptim(streamOrBuffer) -> {stream:optimizedStream, size}
// imOptim.jpgOptim(streamOrBuffer) -> {stream:optimizedStream, size}
// imOptim.svgOptim(streamOrBuffer) -> {stream:optimizedStream, size}
Usage example
var imOptim = require('im-optim');
var fetch = require('node-fetch');
app.get('/:url', (req, res) => { // optimizer proxy: fetch url, optimize and send back
fetch(req.params.url)
.then(s => imOptim(s, s.headers.get('content-type'))
.then(({stream, size}) => {
res.setHeader('content-type', s.headers.get('content-type'));
res.setHeader('content-length', size); // not mandatory
stream.pipe(res);
})
})
.catch(e => res.send(e));
})