Node.js bindings for oxipng.
Optimizes PNG images for size. This is very slow and should only be done for static resources.
const { optimizeOxipng } = require('node-oxipng')
const { readFile, writeFile } = require('fs/promises')
readFile('./raw.png')
.then(buffer => optimizeOxipng(buffer))
.then(buffer => writeFile('./optimized.png', buffer))Type: Uint8Array
Type: Object
See Options for possible values.
Using this function is strongly discouraged. Running oxipng can easily take
more than 30s even on relatively small images (< 1 MB). optimizeOxipngSync
will block the entire process during this time.
Type: Uint8Array
Type: Object
See Options for possible values.
| Name | Type | Default | Description |
|---|---|---|---|
force |
boolean |
false |
Write to output even if there was no improvement in compression. |
optimizationLevel |
number |
2 |
Set the optimization level preset. Valid values are 0 to 6. The default level 2 is quite fast and provides good compression. Lower levels are faster, higher levels provide better compression, though with increasingly diminishing returns. |
optimizationMax |
boolean |
false |
Force the highest optimization level. Overrides optimizationLevel |
optimizeAlpha |
boolean |
false |
Whether to allow transparent pixels to be altered to improve compression. |
interlace |
string |
remove |
Whether to change the interlacing type of the file. Valid values are remove, apply, and keep |
bitDepthReduction |
boolean |
true |
Whether to attempt bit depth reduction. |
colorTypeReduction |
boolean |
true |
Whether to attempt color type reduction. |
paletteReduction |
boolean |
true |
Whether to attempt palette reduction. |
grayscaleReduction |
boolean |
true |
Whether to attempt grayscale reduction. |
idatRecoding |
boolean |
true |
Whether to perform recoding of IDAT and other compressed chunks. If any type of reduction is performed, IDAT recoding will be performed regardless of this setting. |
scale16 |
boolean |
false |
Whether to forcibly reduce 16-bit to 8-bit by scaling. |
stripSafe |
boolean |
false |
Strip safely-removable chunks |
stripAll |
boolean |
false |
Strip all non-critical chunks. Will convert APNGs to standard PNGs. |
stripChunks |
string[] |
[] |
Strip chunks in the list. |
keepChunks |
string[] |
`` | Strip all metadata except chunks in the list. Special value display will includes chunks that affect the image appearance. (Same as stripSafe: true). |
fastEvaluation |
boolean |
false |
Strip safely-removable chunks |
filter |
string[] |
["None", "Sub", "Entropy", "Bigrams"] |
Which filters try on the image. |
compressionLevel |
number |
11 |
Deflate compression level (0-12) for main compression trials. The levels here are defined by the libdeflate compression library. The default value depends on the optimization level preset. |
useZopfli |
boolean |
false |
Use the much slower but stronger Zopfli compressor for main compression trials. |
zopfliIterations |
number |
15 |
Set the number of iterations (1-255) to use for Zopfli compression. Using fewer iterations may speed up compression for large files. |