JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3409
  • Score
    100M100P100Q134645F

node.js wrapper for cwebp

Package Exports

  • cwebp

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cwebp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-webp

Build Status Dependency Status

Node.js wrapper for cwebp binary

Installation

npm install cwebp

Requirements

WebP library should be installed and its binaries should be in $PATH.

Usage

var Webp = require('cwebp');

var webp = new Webp(source);

Available source types

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

var Webp = require('cwebp');

var webp = new Webp('image.jpeg');

It also accepts Buffers and Streams.

var webp = new Webp(buffer);
var webp = new Webp(stream);

Converting image to WebP

webp.write('image.webp', function(err) {
    console.log('converted');
});

Getting converted image as a Buffer

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

Getting converted image as a readable Stream

webp.stream(function(err, stream) {
    // ...
});

Working with Streams and Buffers

Currently WebP library have no inner support for streaming, so it only works with files.

So, when Buffer or Stream is used node-webp creates a temporary file to store its content.

To prevent leaks node-webp creates temporary files only when .write(), .stream() or .toBuffer() is called.

It removes all temporary files after conversion, but before triggering a callback.

So, converting Stream into a Buffer will cause two temporary files to be created and then removed.

It also means that node-webp will start listening for new data in the source stream only when .write(), .stream() or .toBuffer() is called.

Using promises

node-webp supports A+ promises.

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

node-webp use when library.

Specifying conversion options

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

webp.quality(60);

Sending raw command

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