Skip to main content

std.image

std.image loads, inspects, saves, and converts images. BMP is always available (native); PNG and JPEG require libpng/libjpeg at build time.

Reference

load(path) // -> {width, height, format, pixels} (pixels: RGBA8 binary)
info(path) // -> {width, height, format}
save(path, w, h, pixels[, quality = 90]) // format from file extension
convert(in, out[, quality = 90])
capability() // -> {bmp, png, jpg}
FunctionDescription
load(path)Load image → {width, height, format, pixels}
info(path)Inspect without loading pixels → {width, height, format}
save(path, w, h, pixels[, q])Save RGBA8 pixels; format from file extension
convert(in, out[, q])Convert between formats
capability()Which formats are available

pixels is an RGBA8 binary string of width * height * 4 bytes. quality (1–100, default 90) affects JPEG output.

Examples

var caps = std.image.capability()
print(caps.bmp, caps.png, caps.jpg)

var img = std.image.load("photo.png")
print(img.width, "x", img.height, img.format) // e.g. 800 x 600 png
std.image.save("copy.png", img.width, img.height, img.pixels)
std.image.convert("photo.png", "photo.jpg", 85)

// inspect without decoding everything
var meta = std.image.info("a.jpg")
print(meta.width, meta.format)

Paths accept ~ and $VAR expansion.

See also

  • std.file — file primitives for managing image paths
  • Embedding — image backend auto-detection