CrImage::WEBP
WEBP module implements a decoder and encoder for WEBP images. The WEBP specification is at: https://developers.google.com/speed/webp/docs/riff_container
Reading WebP Images
# Read from file
image = CrImage::WEBP.read("image.webp")
# Read from IO
File.open("image.webp", "rb") do |file|
image = CrImage::WEBP.read(file)
end
# Read configuration only (dimensions, color model)
config = CrImage::WEBP.read_config("image.webp")
Writing WebP Images
# Write to file (lossless VP8L format)
CrImage::WEBP.write("output.webp", image)
# Write to IO
File.open("output.webp", "wb") do |file|
CrImage::WEBP.write(file, image)
end
# Write with extended format (VP8X container)
options = CrImage::WEBP::Options.new(use_extended_format: true)
CrImage::WEBP.write("output.webp", image, options)
Constants
WEBP_HEADER = "RIFF".to_slice
Class methods
new_riff_reader(io : IO) : Tuple(FourCC, RIFFReader)
Creates a new RIFF reader from IO stream.
Reads and validates RIFF header, extracts form type (e.g., "WEBP"), and returns a reader for iterating through chunks.
Returns: Tuple of {form_type, riff_reader}
Raises: FormatError if RIFF header is invalid or missing
read and decode the configurations like color model, dimensions
write the Image to file in WebP lossless format
write the Image to IO in WebP lossless format
Nested types
- CrImage::WEBP::BitWriter
- CrImage::WEBP::ChunkReader
- CrImage::WEBP::Decoder
- CrImage::WEBP::Encoder
- CrImage::WEBP::FormatError
- CrImage::WEBP::FourCC
- CrImage::WEBP::HuffmanCode
- CrImage::WEBP::HuffmanEncoder
- CrImage::WEBP::Options
- CrImage::WEBP::RIFFReader
- CrImage::WEBP::TransformEncoder
- CrImage::WEBP::VP8L
- CrImage::WEBP::Writer