Tanguv0.35.0
Math, SIMD & media6 exports
Raw Markdown

/image/jpeg

JPEG image decoder and encoder with configurable quality for files and byte slabs.

(use /image/jpeg)

Functions & symbols#

Coder#

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

Creates a streaming JPEG 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 JPEG encoder settings (e.g. :quality)
Returns:Any
(let coder (jpeg/Coder 800 600 :rgba8 out-file))

decode-from-file#

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

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

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

decode-from-slab#

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

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

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

encode-to-file#

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

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

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

encode-to-slab#

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

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

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

write#

function
(write coder slab) -> None

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

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