3.1.0 • Published 10 days ago

cwebp v3.1.0

Weekly downloads
3,822
License
-
Repository
github
Last release
10 days ago

NPM Package Build Status

node-webp

Node.js wrapper for cwebp and dwebp binaries from WebP image processing utility.

Installation

npm install cwebp

Getting latest version of WebP

You can get latest WebP source, pre-compiled binaries and installation instructions from its official website, or from its downloads repository.

Linux users may use this installation script to automatically download and install the latest WebP binaries:

curl -s https://raw.githubusercontent.com/Intervox/node-webp/latest/bin/install_webp | sudo bash

MacOS users may install WebP using homebrew:

brew install webp

or MacPorts:

sudo port selfupdate
sudo port install webp

If none of it suit your needs, you may build the WebP utilities yourself.

WebP versions compatibility

node-webp versionFully compatible WebP versionsPartially compatible WebP versions
0.1.xall versionsall versions
1.x0.4.1 and laterall versions
2.x0.5.0 and laterall versions

Usage

var CWebp = require('cwebp').CWebp;
var DWebp = require('cwebp').DWebp;

var encoder = new CWebp(source_image);
var decoder = new DWebp(source_webp);

or

// new is optional
var encoder = CWebp(source_image);
var decoder = DWebp(source_webp);

or

// Backward-compatibility with cwebp@0.1.x
var CWebp = require('cwebp');

Specifying path to cwebp binary

By default node-webp looks for cwebp and dwebp binary in your $PATH.

Specifying path as a constructor option

var Webp = require('cwebp');
var binPath = require('webp').cwebp;

var webp = new Webp(source, binPath);

Changing default behaviour

var CWebp = require('cwebp').CWebp;
CWebp.bin = require('webp').cwebp;

var encoder = new CWebp(source);
var DWebp = require('cwebp').DWebp;
DWebp.bin = require('webp').dwebp;

var decoder = new DWebp(source);

N.B.: webp npm module provide old webp 0.3.x binaries.

Available source types

When source is a string node-webp treats it as a file path.

var CWebp = require('cwebp').CWebp;
var DWebp = require('cwebp').DWebp;

var encoder = new CWebp('original.jpeg');
var decoder = new DWebp('converted.webp');

It also accepts Buffers and Streams.

var encoder = new CWebp(buffer);
var decoder = new DWebp(stream);

Note that node-webp will start consuming the input stream only when .write(), .stream() or .toBuffer() is called.

Encoding and decodind WebP images

encoder.write('image.webp', function(err) {
    console.log(err || 'encoded successfully');
});
decoder.write('image.png', function(err) {
    console.log(err || 'decoded successfully');
});

Getting output image as a Buffer

decoder.toBuffer(function(err, buffer) {
    // ...
});

Getting output image as a readable Stream

var stream = encoder.stream();

stream.pipe(destination);
stream.on('error', function(err) {
  // something bad happened
});

Using promises

node-webp supports promises.

encoder.write('image.webp').then(function() {
    // ...
});
encoder.toBuffer().then(function(buffer) {
    // ...
});
decoder.stream().then(function(stream) {
    // ...
});

Specifying conversion options

node-webp provides helper functions for most of cwebp and dwebp conversion options. For the full list of available helpers see methods.json file.

encoder.quality(60);
decoder.tiff();

Sending raw command

encoder.command('-d', 'dump.pgm');

Providing custom spawn options

encoder.spawnOptions({detached: true});

Changelog

3.1.0

10 days ago

2.1.1

7 months ago

2.1.0

7 months ago

3.0.0

7 months ago

2.0.5

4 years ago

2.0.4

5 years ago

2.0.3

6 years ago

2.0.2

7 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.0

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.0

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago