Tanguv0.35.0
Math, SIMD & media4 exports
Raw Markdown

/image

In-memory raster Image decoding/encoding with format detection, cropping, and high-quality resizing.

(use /image)

Functions & symbols#

Image#

constructor
(Image width height encoding data [options]) -> Image

Constructs an `Image` value from pixel dimensions, channel encoding, and a raw `Slab`.

ParameterTypeOptionalDescription
widthIntrequiredImage width in pixels
heightIntrequiredImage height in pixels
encodingKeySymbol | StringrequiredPixel layout encoding (e.g. :rgb8, :rgba8, :luma8)
dataSlabrequiredRaw packed pixel buffer Slab
optionsMapoptionalOptional metadata map
Returns:Any
(let img (image/Image 256 256 :rgba8 raw-slab))

crop#

function
(crop image x y width height) -> Image

Returns a cropped sub-region of `image` at `(x, y)` with size `width x height`.

ParameterTypeOptionalDescription
imageImagerequiredSource image map or Image value
xIntrequiredLeft crop offset in pixels
yIntrequiredTop crop offset in pixels
widthIntrequiredCropped width in pixels
heightIntrequiredCropped height in pixels
Returns:Any
(let thumb (image/crop img 0 0 128 128))

detect-format#

function
(detect-format data) -> (Or KeySymbol None)

Detects the image container format (:png, :jpeg, :webp, :avif, :gif, ...) from encoded file header bytes.

ParameterTypeOptionalDescription
dataSlabrequiredEncoded image header bytes
Returns:Any
(image/detect-format raw-bytes) ; -> :png

resize#

function
(resize image width height [options]) -> Image

Resizes `image` to `width x height` using the configured resampling filter (defaults to Lanczos3).

ParameterTypeOptionalDescription
imageImagerequiredSource image
widthIntrequiredTarget width in pixels
heightIntrequiredTarget height in pixels
optionsMapoptionalOptional {:filter :lanczos3 | :triangle | :nearest}
Returns:Any
(let resized (image/resize img 800 600))