waving android

I am currently a software engineer at Google, where as a member of the Android platform team I build frameworks and user interfaces.

The blog here at is mostly historical; you can find more recent posts on .

MiniPNG for Python.

March 5th, 2006

This article (and ensuing thread) about lightweight Sparklines in Ruby reminded me that I’d intended to write a super-lightweight PNG library (for those times when you want a quick and dirty Web graphic and don’t have a proper graphics toolkit handy).

I don’t really speak Ruby yet (any more than I do Japanese…konban wa, watashi wa dsandler), so here’s minipng.py. Requires: Python 2.x, and nothing else. Currently supported: 8bpp RGB, with optional single-color transparency (tRNS). Sample code:

# should result in a black smiley face on yellow background
from minipng import MiniPNG, Color
mp = MiniPNG(9, 6, Color.YELLOW)
for pt in [(2,1), (6,1), (1,3), (7,3), (2,4), (3,4), (4,4), (5,4), (6,4)]:
    mp.plot(pt, Color.BLACK)
pngdata = mp.to_png()

I’ll probably add grayscale, gray+alpha, and RGBA soon (next time I’m bored and near a computer). [ :) ]

Add a comment

html help (show)

newer: older: