New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

im-optim

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

im-optim

optimize png, jpeg and svg images

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

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));
})

Keywords

image

FAQs

Package last updated on 29 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts