pura-webp
A pure Ruby WebP decoder and encoder with zero C extension dependencies.
Part of the pura-* series — pure Ruby image codec gems.
Features
- VP8 lossy WebP decoding
- VP8L lossless WebP encoding
- No native extensions, no FFI, no external dependencies
- CLI tool included
Installation
gem install pura-webpUsage
require "pura-webp"
# Decode
image = Pura::Webp.decode("photo.webp")
image.width #=> 800
image.height #=> 600
image.pixels #=> Raw RGB byte string
image.pixel_at(0, 0) #=> [r, g, b]
# Encode (VP8L lossless)
Pura::Webp.encode(image, "output.webp")
# Resize
thumb = image.resize(200, 200)
Pura::Webp.encode(thumb, "thumb.webp")Benchmark
Decode performance on a 400×400 WebP image, Ruby 4.0.2 + YJIT:
| Operation | pura-webp | ffmpeg (C + SIMD) | vs ffmpeg |
|---|---|---|---|
| Decode | 207 ms | 66 ms | 3.1× slower |
Why pure Ruby?
-
gem installand go — nobrew install webp, noapt install libwebp-dev - Works everywhere Ruby works — CRuby, ruby.wasm, mruby, JRuby, TruffleRuby
- Edge/Wasm ready — browsers (ruby.wasm), sandboxed environments
- No system library needed — unlike every other Ruby WebP solution
Current Limitations
- Decoder: VP8 lossy only (VP8L lossless and VP8X extended not yet decoded)
- Encoder: VP8L lossless format, works best with images up to ~200×200
- Loop filter not implemented in decoder (slight quality difference)
Related Gems
| Gem | Format | Status |
|---|---|---|
| pura-jpeg | JPEG | ✅ |
| pura-png | PNG | ✅ |
| pura-bmp | BMP | ✅ |
| pura-gif | GIF | ✅ |
| pura-tiff | TIFF | ✅ |
| pura-ico | ICO | ✅ |
| pura-webp | WebP | ✅ |
| pura-image | All formats | ✅ |
License
MIT