webp (Rust)
Encode and decode WebP images in Rust, built on libwebp
Repository Health
Technical Analysis
webp is a thin, safe Rust wrapper around Google’s libwebp (via the libwebp-sys FFI bindings) for encoding and decoding WebP images. Its Encoder type takes raw RGB/RGBA pixel buffers or, with the optional img feature, a DynamicImage from the popular image crate directly, and produces lossy or lossless WebP output at a configurable quality level. The companion Decoder reads WebP bytes back into pixel data and exposes BitstreamFeatures for inspecting a WebP file’s width, height, alpha, and animation flags without fully decoding it.
Beyond static images, the crate includes AnimEncoder/AnimDecoder types for building and reading animated WebP files frame-by-frame. Because it’s a light API surface over libwebp-sys, it’s commonly reached for by Rust image-processing pipelines and CLI tools that need WebP conversion without hand-writing FFI bindings themselves.
What You Get
Encodersupporting raw RGB/RGBA buffers or direct conversion fromimage::DynamicImage- Lossy (
encode(quality)), lossless (encode_lossless()), and fully configurable (encode_advanced(&WebPConfig)) encoding modes Decoderproducing aWebPImagefrom raw WebP bytes, convertible back into standard pixel buffersBitstreamFeaturesfor cheaply inspecting width, height, alpha channel, and animation flags from a WebP fileAnimEncoder/AnimDecoderfor building and reading animated WebP images frame by frame- Optional
imgfeature (on by default) integrating directly with the widely-usedimagecrate’sDynamicImage
Common Use Cases
- Converting JPEG/PNG images to WebP in an image-processing pipeline or CLI tool to reduce file size
- Decoding user-uploaded WebP images into pixel buffers for further processing or re-encoding
- Building or reading animated WebP files (e.g. stickers or short animations) frame by frame
- Inspecting WebP file metadata (dimensions, alpha, animation) cheaply before committing to a full decode
- Integrating WebP support into Rust web services or CLIs already using the
imagecrate for other formats
Under The Hood
Architecture — The crate is a thin four-file wrapper (encoder.rs, decoder.rs, animation_encoder.rs, animation_decoder.rs) around raw libwebp-sys FFI calls, with shared.rs holding common types (PixelLayout, WebPMemory) shared between the static and animated code paths; Encoder/Decoder own borrowed slices and only allocate on encode/decode, keeping the safe-Rust surface small relative to the C library it wraps. Tech Stack — Rust 2021 edition with one core dependency, libwebp-sys (bindings to Google’s C libwebp), and an optional dependency on the image crate (gated behind the default-on img feature) for DynamicImage interop. Code Quality — There is no dedicated tests/ directory in the repository; correctness relies on examples/ demonstrating JPEG↔WebP conversion and on libwebp-sys’s own correctness, and the project has seen low commit activity recently, functioning as a stable, narrow-scope FFI wrapper rather than actively evolving code. API Design — The API mirrors image-crate ergonomics closely (Encoder::from_image(), .encode(quality)) so users already familiar with the image crate can adopt WebP support with almost no new concepts, though the lack of tests means edge cases (malformed input, unusual pixel layouts) are less rigorously guarded than in the underlying image/libwebp libraries themselves.
Used by 3 apps in this directory
DevTools-X
Developer Tools
41 offline-first developer utilities in a single 10MB cross-platform desktop app — no Electron, no cloud, no compromise.
openfootmanager
Game Development
A free and open source football management simulation game built with Rust and Tauri, inspired by Football Manager.
Spacedrive
File Storage · Collaboration
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.