imagemin
Minify images seamlessly
Install
$ npm install --save imagemin
Usage
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
const imageminPngquant = require('imagemin-pngquant');
imagemin(['images/*.{jpg,png}'], 'build/images', {
plugins: [
imageminMozjpeg(),
imageminPngquant({quality: '65-80'})
]
}).then(files => {
console.log(files);
//=> [{data: <Buffer 89 50 4e …>, path: 'build/images/foo.jpg'}, …]
});
API
imagemin(input, output, [options])
Returns a promise for an array of objects in the format {data: Buffer, path: String}
.
input
Type: array
Files to be optimized. See supported minimatch
patterns.
output
Type: string
Set the destination folder to where your files will be written. If no destination is specified no files will be written.
options
useFolderStructure
Type: boolean
Whether or not to keep the folder structure of where the files sit
removePath
Type string
Use together with useFolderStructure
to remove a part of the path not needed when copying the files to the output folder.
For example, if your origin folder is /src/assets/image/level1/level2/
and when copying to your destination you want to keep outputFolder/level1/level2
, just set removePath
to /src/assets/image/
plugins
Type: array
Array of plugins to use.
imagemin.buffer(buffer, [options])
Returns a promise for a buffer.
buffer
Type: buffer
The buffer to optimize.
options
plugins
Type: array
Array of plugins to use.
Related
- imagemin-cli - CLI for this module
- imagemin-app - GUI app for this module
- gulp-imagemin - Gulp plugin
- grunt-contrib-imagemin - Grunt plugin
License
MIT © imagemin