Node.js wrapper for image compression algorithms.
Types
Supporting of other types of images is coming soon.
Patches
You can view all the patches which are applied to the algorithms here.
Overview:
-
optipng.patch – adds to OptiPNG the ability to remove RGB components or transparent pixels in RGB+alpha images.
-
zopflipng.patch – makes Zopflipng work on Linux.
Install
$ npm install imageoptim
This command will install image-optim and all supported compression algorithms automatically. The installation of the compression algorithms is subscribed in script env-setup.
Usage
API
var imageOptim = ;
imageOptim.optim
Optimizes the given files.
@param {String[]} – a list of paths to files to optimize
@param {Object} – options:
- reporters {String[]} - reporters of the results. flat - writes the results to
stdout
, html - creates the HTML report of the results in fileimageoptim-report.html
(default:flat
).
@returns {Promise * Object[]} – the information about optimized files:
name: 'file.ext' savedBytes: 12345 exitCode: 0
imageOptim.lint
Checks whether the given files can be optimized further.
@param {String[]} – a list of paths to files to check
@param {Object} – options:
- tolerance {Number} – sets the measurement error in percentages (decimal
< 1
) or bytes (integer or decimal>= 1
) (default:0
).
type | skope | description |
---|---|---|
percentages | < 1 | The file will be considered to be optimized if the percentage of saved bytes after the compression is less than the specified value (0.8 – 80% , 0.01 – 1% , etc) |
bytes | >= 1 | The file will be considered to be optimized if the number of saved bytes after the compression is less than the specified value (20 – 20 bytes , 100500 – 100500 bytes , etc) |
- reporters {String[]} - reporters of the results. flat - writes the results to
stdout
, html - creates the HTML report of the results in fileimageoptim-report.html
(default:flat
).
@returns {Promise * Object[]} – the information about linted files:
name: 'file.ext' isOptimized: true exitCode: 0
Exit code
imageOptim.SUCCESS
If a file was processed without errors its exit code will be equal to 0
.
imageOptim.CANT_COMPRESS
If a file can not be processed by one of the algorithms its exit code will be equal to 1
.
imageOptim.DOESNT_EXIST
If a file does not exist its exit code will be equal to 2
.
Example
var imageOptim = ; // optimizationimageOptim ; // lintingimageOptim ;
CLI
$ imageoptim --helpNode.js wrapper
REMARK! More information about options lint
and tolerance
can be found in the API.
Example
$ imageoptim path/to/file1 path/to/file2 --reporter=flat --reporter=html # optimization $ imageoptim path/to/file --lint --tolerance=0.08 --reporter=flat --reporter=html # linting, tolerance is `8%` $ imageoptim path/to/file --lint --tolerance=20 # linting, tolerance is `20 bytes`