Manuscript Documentation
v2026.12.0

@std/image/png.ms#

Import each required symbol with import Name from "@std/image/png.ms".

decode_png Function#

Decodes any PNG color type, bit depth and interlacing into an 8-bit raster; 16-bit samples keep their high byte. Indexed images expand to RGB, and a tRNS chunk adds alpha to gray, RGB and indexed images. Malformed data, including a bad chunk checksum, returns EBADMSG. An unsupported feature, such as an unknown critical chunk, returns ENOTSUP, and dimensions past max_pixels or the hard ceiling return EOVERFLOW.

Manuscript
fn decode_png(data Bytes, max_pixels Int? = null) Result[Raster, Error] { ... }

encode_png Function#

Encodes pixels as an 8-bit PNG, choosing a filter for each row. channels 1, 2, 3 and 4 write gray, gray with alpha, RGB and RGBA. A dimension past 2^31 - 1 returns EOVERFLOW.

Manuscript
fn encode_png(width Int, height Int, channels Int, pixels List[UInt8]) Result[Bytes, Error] { ... }