Aug 21 2008
drawing images on google app engine
The google app engine image api looks nice before you actually use it. Why? Because it lacks a fundamental feature: the capability to draw an image. That’s right: no trace of a classic canvas api (setpixel, getpixel, rectangle, circle, etc).
Luckily, some clever programmer wrote a PNGCanvas class that saved the day. Here’s how to use it:
from pngcanvas import PNGCanvas class ImageTest(webapp.RequestHandler): def get(self): img = PNGCanvas(256, 256, [0, 0,0,0]) for i in range(0, 256): img.point(i, i, [0xff, 0, 0, 0xff]) self.response.headers['Content-Type'] = "image/png" self.response.out.write(img.dump())
This example runs at http://pngcanvas.appspot.com/image
Beer donation