webp (Rust)

Encode and decode WebP images in Rust, built on libwebp

Library
Cargo
v0.3.1
89stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
32/100Needs Attention
Development Activity0
Maintenance0
Community48
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
63/100Good
Architecture65
Code Quality58
Innovation45
Learning Curve82

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

  • Encoder supporting raw RGB/RGBA buffers or direct conversion from image::DynamicImage
  • Lossy (encode(quality)), lossless (encode_lossless()), and fully configurable (encode_advanced(&WebPConfig)) encoding modes
  • Decoder producing a WebPImage from raw WebP bytes, convertible back into standard pixel buffers
  • BitstreamFeatures for cheaply inspecting width, height, alpha channel, and animation flags from a WebP file
  • AnimEncoder/AnimDecoder for building and reading animated WebP images frame by frame
  • Optional img feature (on by default) integrating directly with the widely-used image crate’s DynamicImage

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 image crate 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search