node-zopflipng
v2.0.0
Published
Native module for zopflipng
Downloads
106
Maintainers
Readme
node-zopflipng
Node.js bindings for zopflipng.
Optimizes PNG images for size. This is very slow and should only be done for static resources.
Install
$ npm install --save node-zopflipng
Usage
const {optimizeZopfliPng} = require('node-zopflipng');
const {readFile, writeFile} = require('fs/promises');
readFile('./raw.png')
.then(buffer => optimizeZopfliPng(buffer))
.then(buffer => writeFile('./optimized.png', buffer));
API
optimizeZopfliPng(input, [options]): Promise
input
Type: Buffer
options
Type: Object
See Options for possible values.
optimizeZopfliPngSync(input, [options]): Buffer
Using this function is strongly discouraged. Running zopflipng can easily take
more than 30s even on relatively small images (< 1 MB). optimizeZopfliPngSync
will block the entire process during this time.
input
Type: Buffer
options
Type: Object
See Options for possible values.
Options
| Name | Type | Default | Lossless | Description |
|--------------------|------------|------------------------|----------|------------ |
| lossyTransparent
| boolean
| false
| ✗ | Remove colors behind alpha channel 0. No visual difference, removes hidden information. |
| lossy8bit
| boolean
| false
| ✗ | Convert 16-bit per channel image to 8-bit per channel. |
| more
| boolean
| false
| ✓ | Compress more. Uses more iterations depending on file size. |
| iterations
| integer
| 15
/5
(small/large) | ✓ | Number of iterations, more iterations makes it slower but provides slightly better compression. Default: 15 for small files, 5 for large files. Overrides more
option. |
| keepChunks
| string[]
| []
| ✓ | Keep metadata chunks with these names that would normally be removed, e.g. tEXt
, zTXt
, iTXt
, gAMA
. Due to adding extra data, this increases the result size. By default ZopfliPNG only keeps (and losslessly modifies) the following chunks because they are essential: IHDR
, PLTE
, tRNS
, IDAT
and IEND
. |