| Crates.io | zenwebp |
| lib.rs | zenwebp |
| version | 0.2.0 |
| created_at | 2026-01-24 03:14:42.290595+00 |
| updated_at | 2026-01-25 01:53:39.456305+00 |
| description | High-performance WebP encoding and decoding in pure Rust |
| homepage | https://github.com/imazen/zenwebp |
| repository | https://github.com/imazen/zenwebp |
| max_upload_size | |
| id | 2065983 |
| size | 930,054 |
Pure Rust WebP encoding and decoding. No C dependencies, no unsafe code.
Add to your Cargo.toml:
[dependencies]
zenwebp = "0.2"
use zenwebp::WebPDecoder;
let webp_bytes: &[u8] = /* your WebP data */;
let mut decoder = WebPDecoder::new(webp_bytes)?;
let (width, height) = decoder.dimensions();
// Decode to RGBA
let mut rgba = vec![0u8; decoder.output_buffer_size()?];
decoder.read_image(&mut rgba)?;
use zenwebp::{WebPEncoder, EncoderParams, ColorType};
let rgb_pixels: &[u8] = /* your RGB data */;
let (width, height) = (800, 600);
// Lossy encoding at quality 75
let mut webp_output = Vec::new();
let mut encoder = WebPEncoder::new(&mut webp_output);
encoder.set_params(EncoderParams::lossy(75));
encoder.encode(rgb_pixels, width, height, ColorType::Rgb8)?;
#![forbid(unsafe_code)] - memory safety guaranteedalloc, no standard library neededWe achieve both safety and performance through safe abstractions over CPU intrinsics:
wide - portable SIMD types that autovectorize wellarchmage and magetypes - token-gated safe intrinsicssafe_unaligned_simd - safe unaligned load/storecore::arch - newly stabilized as safe in RustThese abstractions may not be perfect, but we trust them over hand-rolled unsafe code.
Supports all WebP features: lossy and lossless compression, alpha channel, animation, and extended format with ICC/EXIF/XMP chunks.
Supports lossy and lossless encoding with configurable quality (0-100) and speed/quality tradeoff (method 0-6).
// Lossless encoding
encoder.set_params(EncoderParams::lossless());
// Fast lossy encoding (larger files)
encoder.set_params(EncoderParams::lossy(75).method(0));
// High quality lossy (slower, smaller files)
encoder.set_params(EncoderParams::lossy(75).method(6));
Benchmarks on a 768x512 image (Kodak test suite):
| Operation | zenwebp | libwebp | Ratio |
|---|---|---|---|
| Decode | 4.2ms | 3.0ms | 1.4x slower |
| Encode (method 4) | 65ms | 75ms* | 1.15x faster |
*libwebp method 6 with trellis, comparable quality settings
At the same quality setting, zenwebp produces files within 1-5% of libwebp's size with comparable visual quality. Quality is slightly better than libwebp below Q75 and slightly worse above Q75.
[dependencies]
zenwebp = { version = "0.2", default-features = false }
Both encoder and decoder work without std. The decoder takes &[u8] slices and the encoder writes to Vec<u8>. Only encode_to_writer() requires the std feature.
Forked from image-webp with significant enhancements:
Licensed under either Apache License, Version 2.0 or MIT license at your option.
Contributions welcome! Please feel free to open issues or pull requests.
Code review recommended for production use.