Esc

read_image_info

procedureextensionsince 0.36.1Source
  • macOS: read_image_info works on macOS
  • Linux: read_image_info works on Linux
  • Windows: read_image_info works on Windows
  • Wasm: read_image_info works on Wasm

Reads the format, size and channel count from the header of a PNG or JPEG without decoding the pixels or allocating. It checks the header only: later chunks, tables and image data may still be damaged, so use decode_image when you need the pixels. Files with more than max_pixels pixels are refused, as in decode_image. Other formats are reported as not supported.

Signature

read_image_info :: (
    data: [] u8,
    max_pixels: s64 = DEFAULT_MAX_PIXELS
) -> (info: Image_Info, ok: bool, error: string)
Example↗
png := encode_png(make_image(5, 3, .RGBA8));
defer free(png.data);

info, ok, error := read_image_info(png);
assert(ok && info.format == .PNG && info.width == 5 && info.height == 3 && info.channels == 4);

_, ok, error = read_image_info(cast([] u8) "not an image");
assert(!ok);

See also