module

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

Source
read(path : String) : CrImage::Image

read and decode the entire image

Source
read(io : IO) : CrImage::Image
Source
read_config(path : String) : CrImage::Config

read and decode the configurations like color model, dimensions

Source
read_config(io : IO) : CrImage::Config
Source
write(path : String, image : CrImage::Image, options : Options | Nil = nil) : Nil

write the Image to file in WebP lossless format

Source
write(io : IO, image : CrImage::Image, options : Options | Nil = nil) : Nil

write the Image to IO in WebP lossless format

Source

Nested types