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 🙏

© 2026 – Pkg Stats / Ryan Hefner

webp-converter

v3.0.1

Published

A small node.js library for converting any image to webp file format or converting webp image to any image file format.

Downloads

44,076

Readme

webp-converter

A small Node.js library for converting images to/from the WebP format. It is a thin, typed wrapper around the official precompiled libwebp command-line tools (cwebp, dwebp, gif2webp, webpmux), which ship bundled with the package — no system install or download step required.

  • Zero runtime dependencies
  • TypeScript types included
  • ESM and CommonJS both supported
  • Node.js >= 18

📖 Full usage guide · 🧪 Runnable examples

Reference docs for the underlying tools: cwebp · dwebp · gif2webp · webpmux

Installation

npm install webp-converter

Importing

// ESM / TypeScript
import webp from 'webp-converter';
// or named: import { cwebp, dwebp } from 'webp-converter';

// CommonJS
const webp = require('webp-converter');

Every conversion function returns a Promise. On Linux/macOS, call grant_permission() once first so the bundled binaries are executable:

webp.grant_permission();

Errors reject. As of 3.0, a failed conversion rejects the Promise (2.x resolved instead). Use try/catch with await, or .catch().

Security. File paths are passed to the binaries verbatim (no shell), so user-supplied filenames are safe. The option argument, however, is split into individual CLI flags — do not pass untrusted input as option, or a caller could inject extra flags (e.g. a second -o to redirect output). Treat option as trusted, developer-controlled configuration.

cwebp — convert any image to WebP

try {
  const response = await webp.cwebp('nodejs_logo.jpg', 'nodejs_logo.webp', '-q 80');
  console.log(response);
} catch (err) {
  console.error('conversion failed', err);
}

Pass '-v' as the optional 4th logging argument for verbose libwebp output (defaults to '-quiet').

dwebp — convert WebP to another format

await webp.dwebp('nodejs_logo.webp', 'nodejs_logo.jpg', '-o');

gwebp — convert a GIF to WebP

await webp.gwebp('linux_logo.gif', 'linux_logo.webp', '-q 80');

Buffers and base64

import { readFile } from 'node:fs/promises';

// image buffer -> webp buffer
const webpBuffer = await webp.buffer2webpbuffer(await readFile('nodejs_logo.jpg'), 'jpg', '-q 80');

// base64 image string -> base64 webp string
const base64 = (await readFile('nodejs_logo.jpg')).toString('base64');
const webpBase64 = await webp.str2webpstr(base64, 'jpg', '-q 80');

Both accept an optional final extra_path argument to use your own directory for intermediate files (otherwise a folder under os.tmpdir() is created automatically). Temp files are cleaned up after each call.

webpmux — metadata and animation

webpmux has no logging flag; the trailing logging argument on these functions is accepted for compatibility but ignored.

// Add / extract / strip ICC ('icc'), XMP ('xmp') or EXIF ('exif')
await webp.webpmux_add('in.webp', 'icc_container.webp', 'image_profile.icc', 'icc');
await webp.webpmux_extract('anim_container.webp', 'image_profile.icc', 'icc');
await webp.webpmux_strip('icc_container.webp', 'without_icc.webp', 'icc');

// Build an animated WebP from frames
const frames = [
  { path: './frames/tmp-0.webp', offset: '+100' },
  { path: './frames/tmp-1.webp', offset: '+100' },
  { path: './frames/tmp-2.webp', offset: '+100' },
];
await webp.webpmux_animate(frames, 'anim_container.webp', '10', '255,255,255,255');

// Extract a single frame
await webp.webpmux_getframe('anim_container.webp', 'frame_2.webp', '2');

Frame offset follows the webpmux FRAME_OPTIONS syntax (+di[+xi+yi[+mi[bi]]]); loop of 0 loops forever; bgcolor is A,R,G,B. See the webpmux docs for details.

Using your own / newer binaries

By default the library uses the libwebp binaries bundled under bin/. To point it at a different set — a newer libwebp release, or a platform not bundled (e.g. linux-arm64) — give it a directory containing the tools directly (cwebp, dwebp, gif2webp, webpmux; add .exe on Windows):

import webp from 'webp-converter';

webp.setBinaryDir('/opt/libwebp-1.7.0/bin'); // pass undefined to reset to bundled

Or set it without touching code via an environment variable:

WEBP_CONVERTER_BIN_DIR=/opt/libwebp-1.7.0/bin node app.js

Resolution order is: setBinaryDir()WEBP_CONVERTER_BIN_DIR → bundled binary for the current platform. A directory set this way also works on platforms the package does not bundle binaries for.

Documentation & examples

  • docs/USAGE.md — full API reference, temp-file handling, security notes, and troubleshooting.

  • examples/ — runnable scripts for every feature:

    npm install && npm run build
    node examples/01-image-to-webp.mjs

    | Example | Shows | | --------------------------- | ---------------------------------------- | | 01-image-to-webp.mjs | cwebp — image → WebP | | 02-webp-to-image.mjs | dwebp — WebP → image | | 03-gif-to-webp.mjs | gwebp — GIF → WebP | | 04-buffers-and-base64.mjs | in-memory buffer / base64 conversion | | 05-metadata.mjs | webpmux ICC/XMP/EXIF add·extract·strip | | 06-animation.mjs | build & read animated WebP | | 07-custom-binaries.mjs | setBinaryDir / env var | | commonjs.cjs | CommonJS require usage |

Migrating from 2.x

The function names and argument order are unchanged. Review these behavior changes (full list in CHANGELOG.md):

  • Failed conversions now reject — add error handling.
  • Node >= 18 is required.
  • webpmux_* calls that relied on the default logging now actually succeed (they silently failed in 2.x).

License

MIT