imagemin
v9.0.0
Published
Minify images seamlessly
Downloads
4,058,940
Maintainers
Readme
imagemin
Minify images seamlessly
Install
npm install imagemin
Usage
import imagemin from 'imagemin';
import imageminJpegtran from 'imagemin-jpegtran';
import imageminPngquant from 'imagemin-pngquant';
const files = await imagemin(['images/*.{jpg,png}'], {
destination: 'build/images',
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.6, 0.8]
})
]
});
console.log(files);
//=> [{data: <Uint8Array 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]
API
imagemin(input, options?)
Returns Promise<object[]>
in the format {data: Uint8Array, 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
The plugins to use.
glob
Type: boolean
Default: true
Enable globbing when matching file paths.
imagemin.buffer(data, options?)
Returns Promise<Uint8Array>
.
data
Type: Uint8Array
The image data to optimize.
options
Type: object
plugins
Type: Array
Plugins to use.
Related
- imagemin-cli - CLI for this module
- gulp-imagemin - Gulp plugin