npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cwebp

v3.1.0

Published

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

Downloads

9,596

Readme

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 version | Fully compatible WebP versions | Partially compatible WebP versions | | -------------------- | ------------------------------ | ---------------------------------- | | 0.1.x | all versions | all versions | | 1.x | 0.4.1 and later | all versions | | 2.x | 0.5.0 and later | all 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 [email protected]
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