WEBPery

libwebp is Google's reference WebP library. How to install it, the binaries it ships, and its simple and advanced encode and decode APIs.

libwebp: Installation, Tools, and the C API

libwebp is Google's open-source reference implementation of WebP, written in C and released under a BSD licence. It provides the encode and decode APIs that power every official WebP tool and most third-party WebP support. This guide covers installing it, the command-line binaries it ships, and the structure of its C API.

For the format itself, see What is WebP?. For the command-line tools built on it, see cwebp Command-Line Tool: Full Reference Guide.

What is libwebp?

libwebp is the official WebP library maintained by Google as the format's reference implementation. It encodes and decodes both lossy (VP8) and lossless (VP8L) WebP, including alpha and animation. Browsers, image editors, and language bindings rely on libwebp for WebP support.

libwebp defines the behaviour described by RFC 9649. Its source lives in Google's WebM repository and is permissively licensed for commercial use.

How do you install libwebp?

Install libwebp from your system package manager on Linux and macOS, or build it from source for the latest version. The package installs the shared library and the command-line binaries together.

By platform:

  • Debian / Ubuntusudo apt install webp
  • Fedorasudo dnf install libwebp libwebp-tools
  • macOS (Homebrew)brew install webp
  • Windows — download the precompiled binaries from Google's WebP downloads.
# Build from source
git clone https://chromium.googlesource.com/webm/libwebp
cd libwebp && ./autogen.sh && ./configure && make && sudo make install

Which binaries does libwebp include?

libwebp ships several command-line tools alongside the library. Each wraps a part of the library's functionality for terminal use.

The bundled binaries are:

  • cwebp — encode images to WebP. See cwebp.
  • dwebp — decode WebP to other formats. See dwebp.
  • gif2webp — convert animated GIF to animated WebP.
  • img2webp — build an animated WebP from a sequence of frames.
  • webpmux — assemble, extract, and edit WebP chunks (alpha, animation, metadata).
  • webpinfo — print a WebP file's structure and chunks.
  • vwebp — preview a WebP file in a window.

The animation tools relate to WebP Animation; webpmux operates on the chunks described in WebP File Structure.

What is the libwebp simple API?

The simple API encodes or decodes a whole image in one function call. Encoding functions such as WebPEncodeRGBA take a pixel buffer and quality and return a WebP byte buffer. Decoding functions such as WebPGetInfo and WebPDecodeRGBA read a WebP buffer back to pixels.

#include <webp/encode.h>

uint8_t* output;
size_t size = WebPEncodeRGBA(rgba, width, height, stride, quality, &output);
// write `output` (size bytes) to a .webp file, then WebPFree(output);

The simple API suits straightforward one-shot conversions where you do not need per-parameter control.

What is the libwebp advanced API?

The advanced API exposes full control through WebPConfig and WebPPicture structures. You set every encoder parameter — method, near-lossless, alpha quality, preprocessing — then call WebPEncode. It mirrors the options available in cwebp.

WebPConfig config;
WebPConfigInit(&config);
config.quality = 80;
config.method = 6;            // encoder effort 0–6
WebPConfigPreset(&config, WEBP_PRESET_PHOTO, 80);

The parameters map directly to the flags documented in WebP Compression Settings.

Which languages can use libwebp?

Most languages access WebP through bindings that wrap libwebp. Node's sharp and imagemin, Python's Pillow, Go's golang.org/x/image/webp, and Rust's image crate all rely on or reimplement libwebp's behaviour. This makes WebP available without calling the C library directly.

For Node build pipelines using these bindings, see Batch Converting Images to WebP: CLI and Automated Workflows.

Where to go from here

libwebp is the foundation of the entire WebP ecosystem. Install it for the command-line tools, link it for native encoding, or reach it indirectly through a language binding like sharp.

What is WebP? A Complete Guide to the WebP Image Format

WebP is Google's image format with lossy and lossless compression. Learn how it works, browser support, file sizes, transparency, and animation.

WebP Transparency: Alpha Channel Support

WebP supports an 8-bit alpha channel in lossy and lossless modes. How transparency is stored, the ALPH chunk, file-size cost, and PNG comparison.

srcset and WebP: Responsive Images with Format Fallback

Use srcset and sizes to serve responsive WebP at the right resolution per device, with a JPEG fallback. Width and density descriptors explained.

WebP File Structure: RIFF Container and Chunk Format

How a WebP file is structured: the RIFF container, the WEBP FourCC, and VP8, VP8L, VP8X, ALPH, ANIM and ANMF chunks. The byte layout explained clearly.