WEBPery
Published

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.

WebP and Open Source: libwebp Licensing

Is WebP open source and royalty-free? The libwebp BSD licence, the additional patent grant, the WebM repository, and what it means for commercial use.

WebP and PageSpeed: Serve Next-Gen Image Formats

Google PageSpeed flags images that should use next-gen formats. What the warning means, how WebP fixes it, and how to verify the savings.

WebP on iOS and macOS: Safari Support

WebP works on iOS and macOS since Safari 14 and Big Sur (2020). What Safari, Preview, Photos, and Mail support, and older versions.

WebP in Email: Is It Supported in HTML Emails?

WebP is not reliably supported in HTML email. Which clients render it, why most do not, and what formats to use for newsletters instead.