node.js wrapper for cwebp and dwebp binaries from WebP image processing utility
npm install cwebp
Linux users may use this installation script to automatically download and install latest WebP binaries:
curl -s https://raw.githubusercontent.com/Intervox/node-webp/latest/bin/install_webp | sudo bash
MacOS users may install WebP using MacPorts:
sudo port selfupdate sudo port install webp
If none of it suit your needs, you may build the WebP utilities yourself.
MacOS users may install webp
0.4.0 using homebrew:
brew install webp
You may also install webp
0.3.x as npm module:
npm install webp
Old versions of WebP (prior to
are not compatible with the latest
If you're using old version of WebP, please,
Check this section for more info about new streaming features of the latest WebP version.
var CWebp = require'cwebp'CWebp;var DWebp = require'dwebp'DWebp;var encoder = source_image;var decoder = source_webp;
// new is optionalvar encoder = CWebpsource_image;var decoder = DWebpsource_webp;
// Backward-compatibility with firstname.lastname@example.org CWebp = require'cwebp';
node-webp looks for
dwebp binary in your
var Webp = require'cwebp';var binPath = require'webp'cwebp;var webp = source binPath;
var CWebp = require'cwebp'CWebp;CWebpbin = require'webp'cwebp;var encoder = source;
var DWebp = require'cwebp'DWebp;DWebpbin = require'webp'dwebp;var decoder = source;
webp npm module provide old
webp 0.3.x binaries.
When source is a string
node-webp treats it as a file path.
var CWebp = require'cwebp'CWebp;var DWebp = require'dwebp'DWebp;var encoder = 'original.jpeg';var decoder = 'converted.webp';
It also accepts Buffers and Streams.
var encoder = buffer;
var decoder = stream;
node-webp will start listening to the data in a source stream
.toBuffer() is called.
encoderwrite'image.webp'console.logerr || 'encoded successfully';;
decoderwrite'image.png'console.logerr || 'decoded successfully';;
var stream = encoderstream;streampipedestination;streamon'error'// something bad happened;
Different versions of WebP have different level of streaming support:
|Feature||Older WebP versions||WebP 0.4.1||node-webp 0.1.x||node-webp 1.x|
|cwebp stdin streaming||no||no||mock||mock|
|cwebp stdout streaming||no||native||mock||native|
|dwebp stdin streaming||no||native||mock||native|
|dwebp stdout streaming||no||native||mock||native|
mock means that
node-webp acts as if the feature is supported,
mocking it using temporary files.
So, converting Stream into a Buffer with node-webp
0.x will cause
two temporary files to be created and then removed
(one to store input stream, and another to read output buffer from).
node-webp native streaming will work only
if your WebP version have native support for the corresponding stream,
while mock streaming will work with any version of WebP.
IMPORTANT: If you're using old version of WebP, please,
node-webp supports A+ promises.
node-webp uses when.js library.
node-webp provides helper functions for most of
dwebp conversion options.
For the full list of available helpers see methods.json file.
node-webp returns any error reported by
By default it uses standard error reporting mode,
but it's possible to enable
cwebp verbose error reporting.
var CWebp = require'cwebp'CWebp;sourceverbosetoBuffer// err.message contains verbose error;
dwebp don't support verbose error reporting.
var CWebp = require'cwebp'CWebp;CWebpverbose = true;sourcetoBuffer// err.message contains verbose error;