Skip to content
io
png
read_png

read_png

Mojo function 🡭

read_png

fn def read_png(path: String) -> Canvas

Read a PNG file into a Canvas. Handles 8-bit depth, color types 0/2/4/6 at 8 or 16 bits, interlaced or not; anything else raises (see this module’s docstring).

Every chunk’s CRC-32 is checked against its trailing 4 bytes, and the decompressed data’s Adler-32 against the zlib stream’s, so a corrupted or truncated file is rejected rather than misdecoded.

Args:

  • path (String): File path to read.

Returns:

Canvas: The decoded image as a Canvas, with any alpha channel preserved per pixel.

Raises:

Error: path can’t be read, isn’t a valid PNG, uses an unsupported color type/bit depth/interlacing, or fails a checksum.