module

CrImage::WEBP::Encoder

Encoder handles WebP image encoding.

Provides methods for encoding images to WebP lossless format (VP8L). Handles image conversion, bitstream generation, and RIFF container creation.

Class methods

write(path : String, img : CrImage::Image | Nil, options : Options | Nil = nil) : Nil

Encodes image to file path.

Writes the image to a WebP file using lossless VP8L compression.

Parameters:

  • path : Output file path
  • img : Image to encode (must not be nil)
  • options : Optional encoding options

Raises:

  • ArgumentError if image is nil or dimensions are invalid
  • IO::Error if file write fails

Example:

img = CrImage.read("photo.png")
CrImage::WEBP::Encoder.write("output.webp", img)
Source
write(io : IO, img : CrImage::Image | Nil, options : Options | Nil = nil) : Nil

Encodes image to IO stream.

Writes the image to an IO stream in WebP lossless format. Performs validation, format conversion, and bitstream generation.

Parameters:

  • io : Output IO stream
  • img : Image to encode (must not be nil)
  • options : Optional encoding options

Raises:

  • ArgumentError if image is nil or dimensions invalid (1-16384 pixels)
  • IO::Error if stream write fails
  • OverflowError if arithmetic overflow occurs during encoding

Example:

File.open("output.webp", "wb") do |file|
  CrImage::WEBP::Encoder.write(file, img)
end
Source