Tanguv0.35.0
Math, SIMD & media6 exports
Raw Markdown

/image/webp

WebP image decoder and encoder for files and byte slabs.

(use /image/webp)

Functions & symbols#

Coder#

constructor
(Coder width height encoding writable [options]) -> Coder

Creates a streaming WebP encoder writing rows directly to `writable`.

ParameterTypeOptionalDescription
widthIntrequiredOutput width in pixels
heightIntrequiredOutput height in pixels
encodingKeySymbol | StringrequiredInput pixel encoding (:rgb8, :rgba8, :luma8)
writableStream | FilerequiredDestination writable stream or file handle
optionsMapoptionalOptional WebP encoder settings (e.g. :quality)
Returns:Any
(let coder (webp/Coder 800 600 :rgba8 out-file))

decode-from-file#

function
(decode-from-file path) -> Image

Decodes a WebP file from disk into an in-memory `Image`.

ParameterTypeOptionalDescription
pathStringrequiredPath to input .webp file
Returns:Any
(let img (webp/decode-from-file "photo.webp"))

decode-from-slab#

function
(decode-from-slab data) -> Image

Decodes WebP bytes from a `Slab` into an `Image`.

ParameterTypeOptionalDescription
dataSlabrequiredEncoded WebP byte Slab
Returns:Any
(let img (webp/decode-from-slab bytes))

encode-to-file#

function
(encode-to-file path image [options]) -> None

Encodes `image` as WebP and writes the result directly to `path`.

ParameterTypeOptionalDescription
pathStringrequiredDestination file path
imageImagerequiredImage map or Image value to encode
optionsMapoptionalOptional WebP encoder options
Returns:Any
(webp/encode-to-file "out.webp" img)

encode-to-slab#

function
(encode-to-slab image [options]) -> Slab

Encodes `image` into an in-memory WebP byte `Slab`.

ParameterTypeOptionalDescription
imageImagerequiredImage map or Image value to encode
optionsMapoptionalOptional WebP encoder options
Returns:Any
(let encoded (webp/encode-to-slab img))

write#

function
(write coder slab) -> None

Writes encoded pixel bytes through an open WebP streaming `Coder`.

ParameterTypeOptionalDescription
coderCoderrequiredActive streaming Coder instance
slabSlabrequiredPacked pixel buffer Slab to encode
Returns:Any
(webp/write coder pixels)