cute_png
PNG decoding and encoding backed by the bundled cute_png library.
Optional module
Enable PK_BUILD_MODULE_CUTE_PNG=ON; see build configuration.
Encode and decode in memory
from cute_png import Image
from vmath import color32
image = Image(2, 2)
image.clear(color32(0, 0, 0, 255))
image.setpixel(1, 0, color32(255, 0, 0, 255))
data = image.to_png_bytes()
restored = Image.from_bytes(data)
assert restored.width == 2
assert restored.height == 2
assert restored.getpixel(1, 0) == color32(255, 0, 0, 255)
Coordinates use (x, y), and must be within the image.
File operations require an accessible host filesystem.
For scripts using array2d, loads(data) returns an
array2d[color32] and dumps(grid) returns PNG bytes.
Full signatures, including paste:
cute_png.pyi.