Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cwebp

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cwebp

node.js wrapper for cwebp

  • 0.1.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
639
decreased by-36.16%
Maintainers
1
Weekly downloads
 
Created
Source

node-webp

Build Status Dependency Status

Node.js wrapper for cwebp binary

Installation

npm install cwebp

Getting WebP

You can get WebP source, precompiled binaries and installation instructions from its official website, or from its downloads repository.

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

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

MacOS users may install WebP using homebrew:

brew install webp

As an alternative you may install webp as npm module:

npm install webp

Usage

var Webp = require('cwebp');

var webp = new Webp(source);

or

var webp = Webp(source); // new is optional

Specifying path to cwebp binary

By default node-webp looks for cwebp 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 Webp = require('cwebp');
Webp.bin = require('webp').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');
Verbose errors reporting

node-webp returns any error reported by cwebp. By default it uses standard cwebp error reporting mode, but it's possible to enable verbose error reporting.

var Webp = require('cwebp');

new Webp(source).verbose().toBuffer(function (err, res) {
    // err.message contains verbose error
});
Changing default behaviour
var Webp = require('cwebp');
Webp.verbose = true;

new Webp(source).toBuffer(function (err, res) {
    // err.message contains verbose error
});

Changelog

Keywords

FAQs

Package last updated on 17 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc