pngio
Tool
tools/formats/pngio.py(program, Formats). Read and write PNG pictures with the standard library alone.
Run it with ./gameframe run pngio ARGS or python3 tools/formats/pngio.py. Source on GitHub.
Its own help
This is the help text in the tool itself, as ./gameframe tool pngio prints it.
text
Read and write PNG pictures with the standard library alone.
from pngio import read_png, write_png, grey
w, h, rgb = read_png('shot.png') # rgb: bytes, 3 per pixel, rows top to bottom
write_png('out.png', w, h, rgb)
g = grey(w, h, rgb) # one byte per pixel
Usage: pngio.py FILE print the size, colour type and bit depth
It reads 8-bit greyscale, grey with alpha, RGB, RGBA and palette pictures (bit depth 8, or 1, 2
and 4 for palette and grey), with every filter. Alpha is dropped. It writes 8-bit RGB.
What it does not read: interlaced (Adam7) or 16-bit pictures. Convert those first, for example
with `sips -s format png` on macOS or ImageMagick's `convert -depth 8 -interlace none`.