Image Library (Image)
Image is in the Python package, the CLI, and Rust with the image feature. It isn't in the JavaScript package, so the examples below don't run on this site. An image loads into a document as a Data<Image> value, from bytes or by importing an image file, and every function on this page works on that value.
Loading
Image::from_blob(bytes: blob) -> Data<Image>
Creates an image on the calling object from raw bytes, detecting the format. The bytes can come from anywhere: fs.read, an Http response, or the host.
const bytes = fs::read("photo.png");
const img = Image::from_blob(bytes);
Reading Dimensions
Image::width(img: Data<Image>) -> int
const width = Image::width(img);
Image::height(img: Data<Image>) -> int
const height = Image::height(img);
Transformations
Every function in this section mutates the image in place and returns nothing — call it, then export or continue transforming the same img value.
Image::grayscale(img: Data<Image>) -> void
Image::grayscale(img);
Image::invert(img: Data<Image>) -> void
Image::invert(img);
Image::blur(img: Data<Image>, blur: float) -> void
Gaussian blur — blur is the sigma value.
Image::blur(img, 2.5);
Image::fast_blur(img: Data<Image>, blur: float) -> void
Same gaussian blur as Image.blur, trading some quality for speed — reach for this one over blur if you're processing images in bulk and the difference isn't visually significant for your use case.
Image::fast_blur(img, 2.5);
Image::brighten(img: Data<Image>, brighten: int) -> void
Positive brightens, negative darkens.
Image::brighten(img, 20);
Image::contrast(img: Data<Image>, contrast: float) -> void
Positive increases contrast, negative decreases it.
Image::contrast(img, 15.0);
Image::flip_horizontal(img: Data<Image>) -> void
Image::flip_horizontal(img);
Image::flip_vertical(img: Data<Image>) -> void
Image::flip_vertical(img);
Image::rotate_90(img: Data<Image>) -> void
Clockwise.
Image::rotate_90(img);
Image::rotate_180(img: Data<Image>) -> void
Image::rotate_180(img);
Image::rotate_270(img: Data<Image>) -> void
Clockwise — equivalent to a 90° counter-clockwise rotation.
Image::rotate_270(img);
Resizing
Each of these returns a bool — whether the resize actually succeeded.
Image::resize(img: Data<Image>, width: int, height: int) -> bool
Preserves aspect ratio — the result fits within width × height but may not match it exactly.
const resized = Image::resize(img, 800, 600);
Image::resize_exact(img: Data<Image>, width: int, height: int) -> bool
Forces the exact dimensions given, ignoring the original aspect ratio.
const resized = Image::resize_exact(img, 800, 600);
Image::thumbnail(img: Data<Image>, width: int, height: int) -> bool
Same as resize, but optimized for shrinking rather than resizing in either direction.
const made = Image::thumbnail(img, 128, 128);
Image::thumbnail_exact(img: Data<Image>, width: int, height: int) -> bool
thumbnail's exact-dimensions counterpart, the same way resize_exact relates to resize.
const made = Image::thumbnail_exact(img, 128, 128);
Exporting
Each function below turns the current state of img — after whatever transformations have run — into raw bytes of a specific format.
Image::blob(img: Data<Image>) -> blob
The default export — raw bytes in PNG format, equivalent to Image.png.
const bytes = Image::blob(img);
Image::png(img: Data<Image>) -> blob
const bytes = Image::png(img);
Image::jpeg(img: Data<Image>) -> blob
const bytes = Image::jpeg(img);
Image::webp(img: Data<Image>) -> blob
const bytes = Image::webp(img);
Image::gif(img: Data<Image>) -> blob
const bytes = Image::gif(img);
Image::bmp(img: Data<Image>) -> blob
const bytes = Image::bmp(img);
Image::ico(img: Data<Image>) -> blob
const bytes = Image::ico(img);
Image::tiff(img: Data<Image>) -> blob
const bytes = Image::tiff(img);