Skip to content
Minify images seamlessly
JavaScript
Branch: master
Clone or download
Latest commit 3623867 Sep 1, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Minor tweaks May 12, 2017
.gitattributes Meta tweaks Jul 23, 2018
.gitignore Meta tweaks Sep 5, 2017
.npmrc Meta tweaks Sep 5, 2017
.travis.yml Fix Travis Jun 30, 2019
fixture-corrupt.jpg Use promise based API (#162) Apr 29, 2016
fixture.jpg Use promise based API (#162) Apr 29, 2016
fixture.svg Stop returning original file when the optimization is larger than the… Dec 25, 2018
index.js Rename `output` option to `destination` Jun 30, 2019
license Meta tweaks Jul 23, 2018
package.json 7.0.0 Jun 30, 2019
readme.md
test.js Rename `output` option to `destination` Jun 30, 2019

readme.md

imagemin Build Status

Minify images seamlessly

Install

$ npm install imagemin

Usage

const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
const imageminPngquant = require('imagemin-pngquant');

(async () => {
	const files = await imagemin(['images/*.{jpg,png}'], {
		destination: 'build/images',
		plugins: [
			imageminJpegtran(),
			imageminPngquant({
				quality: [0.6, 0.8]
			})
		]
	});

	console.log(files);
	//=> [{data: <Buffer 89 50 4e …>, path: 'build/images/foo.jpg'}, …]
})();

API

imagemin(input, options?)

Returns Promise<object[]> in the format {data: Buffer, sourcePath: string, destinationPath: string}.

input

Type: string[]

File paths or glob patterns.

options

Type: object

destination

Type: string

Set the destination folder to where your files will be written. If no destination is specified, no files will be written.

plugins

Type: Array

Plugins to use.

glob

Type: boolean
Default: true

Enable globbing when matching file paths.

imagemin.buffer(buffer, options?)

Returns Promise<Buffer>.

buffer

Type: Buffer

Buffer to optimize.

options

Type: object

plugins

Type: Array

Plugins to use.

Related

You can’t perform that action at this time.