Pages

Saturday, January 11, 2014

pngcanvas is a minimalist pure Python library by Rui Carmo that lets you create PNG images from programs.

I only did a quick trial of it by modifying the test_pngcanvas.py program that comes with it - mainly stripping it down to the minimum needed to create a PNG file (since the program is more about testing the library than being an introductory example).

Here is my modified version, try_pngcanvas.py - some of the imports may not be needed:

The program worked on the first try, no tweaking needed - a tribute to the author of pngcanvas.

Subjectively, it also seemed to run fast, though the image created is small.

Update: In my initial version, I had deleted the code to create a gradient. That was when the program ran fast. When I added the gradient code back, it ran significantly slower. Like, less than a second, vs. maybe 2 seconds. Not timed, just guessed. (It can be timed, of course, using various methods.) But considering that generating a gradient is a lot more work than just drawing lines, it seems not bad, at least relatively speaking.
I had also blogged some time ago about pypng, another such library:pypng, pure Python module to encode/decode PNG