imagemin
image optimization tool
TLDR
SYNOPSIS
imagemin path|glob ... --out-dir=dir [--plugin=name ...]imagemin file > output
DESCRIPTION
imagemin is the command-line interface of the imagemin Node.js library. It minifies PNG, JPEG, GIF and SVG images using plugins and can convert to formats such as WebP.By default it uses gifsicle, jpegtran, optipng and svgo (lossless). Other plugins such as mozjpeg, pngquant or webp must be installed separately as imagemin-name packages.
PARAMETERS
-o, --out-dir dir
Output directory. Without it, a single input is written to stdout.-p, --plugin name
Use the named plugin (the imagemin- prefix is omitted). Can be repeated. Overrides the default plugins.--plugin.name.option=value
Pass an option to a plugin. Repeat the flag to build an array value.
PLUGINS
imagemin-optipng Lossless PNG optimization (default)
imagemin-gifsicle GIF optimization (default)
imagemin-svgo SVG optimization (default)
imagemin-mozjpeg Lossy JPEG compression
imagemin-pngquant Lossy PNG compression
imagemin-webp WebP conversion
NODE.JS USAGE
import imageminMozjpeg from 'imagemin-mozjpeg';
await imagemin(['images/*.jpg'], {
destination: 'dist/images',
plugins: [imageminMozjpeg({quality: 75})]
});
CAVEATS
Requires Node.js; install with npm install --global imagemin-cli. Current versions are ESM-only. Many plugins wrap native binaries that are downloaded or compiled at install time, which frequently fails on newer Node.js versions or unusual platforms. Lossy plugins reduce quality. Pointing --out-dir at the source directory overwrites the originals. Development has slowed considerably; plugins are rarely updated.
HISTORY
imagemin was created by Kevin Martensson and is maintained under the imagemin GitHub organization with Sindre Sorhus. It became a standard image optimization step in Grunt, Gulp and webpack build pipelines.
