Registry / devops / image-2-min

image-2-min

JSON →
library6.0.2jsnpmunverified

Image minifier for Node.js that preserves folder structure during compression. Version 6.0.2, stable, low release cadence. Supports JPEG, PNG, GIF, SVG via plugins like imagemin-jpegtran and imagemin-pngquant. Differentiates from other minifiers by automatically mirroring input directory structure in output. Known as a quick solution for batch image optimization but relies on external plugin packages.

npm install image-2-min
INSTALL
IMPORT
SIG · IMAGE-2-MIN
I
image-2-min
devopsjavascriptv6.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

imagemin
import imagemin from 'image-2-min'
const imagemin = require('image-2-min')
Package supports both ESM and CJS; ESM is preferred for modern projects.
imagemin.buffer
import imagemin from 'image-2-min'; const buffer = await imagemin.buffer(inputBuffer)
import { buffer } from 'image-2-min'
buffer is a method on the default export, not a named export.
imageminJpegtran
import imageminJpegtran from 'imagemin-jpegtran';
const imageminJpegtran = require('imagemin-jpegtran');
Plugins are separate packages; must be installed and imported separately.

Minify all JPEG and PNG images in the 'images' folder, preserving directory structure, and output to 'build/images'.

import imagemin from 'image-2-min'; import imageminJpegtran from 'imagemin-jpegtran'; import imageminPngquant from 'imagemin-pngquant'; async function minifyImages() { const files = await imagemin( ['images/*.{jpg,png}'], 'build/images', { plugins: [ imageminJpegtran()(), imageminPngquant({ quality: '65-80' }) ] } ); console.log('Minified files:', files); } minifyImages();
Debug
Known issues
breakingThe API changed from returning an array of objects with 'path' and 'data' properties to returning Promises that resolve to file contents.
fix
Use async/await or .then() to handle returned files.
affects: >=4.0.0
deprecatedimagemin.buffer is deprecated; use file buffer handling instead.
fix
Avoid using imagemin.buffer; process buffers directly with the main function.
affects: >=5.0.0
gotchaPlugins must be called as functions (e.g., imageminJpegtran()()) — forgetting the double call leads to errors.
fix
Always invoke plugin factories twice: once to get the plugin function, again to invoke it.
affects: >=0.0.0
gotchaThe input array uses glob patterns; must include the file extension or pattern — passing a directory without a glob will fail.
fix
Use patterns like 'images/**/*.{jpg,png}' instead of 'images/'.
affects: >=0.0.0
breakingDropped support for Node.js <4; older versions will cause runtime errors.
fix
Upgrade to Node.js 4 or later, or use an older version of the package.
affects: >=6.0.0
Errors
Common errors & fixes
Error: Cannot find module 'imagemin-jpegtran'
imagemin-jpegtran is not installed or not listed in dependencies.
fix
Install the package: npm install imagemin-jpegtran
TypeError: imagemin is not a function
Importing the package incorrectly, e.g., using named import instead of default import.
fix
Use default import: import imagemin from 'image-2-min'
TypeError: imageminJpegtran is not a function
Forgot to call the plugin factory twice: imageminJpegtran()() instead of imageminJpegtran.
fix
Use imageminJpegtran()() in the plugins array.
Upgrade
Version history
6.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
image-2-min — npm install image-2-min · libregistry