2.0.0 • Published 1 year ago

node-zopflipng v2.0.0

Weekly downloads
5
License
(MIT AND Apache-2...
Repository
github
Last release
1 year ago

node-zopflipng

npm Built on N-API v3 CI

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

NameTypeDefaultLosslessDescription
lossyTransparentbooleanfalseRemove colors behind alpha channel 0. No visual difference, removes hidden information.
lossy8bitbooleanfalseConvert 16-bit per channel image to 8-bit per channel.
morebooleanfalseCompress more. Uses more iterations depending on file size.
iterationsinteger15/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.
keepChunksstring[][]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.