PythonImagingLibrary
This is really just to get you started, PIL is huge.
This gives you a quite dull black to grey scale:
1 import Image
2
3 I = Image.new('L', (32, 32))
4 for z in range(32*32): I.putpixel((z % 32,z / 32), z/4)
5
6 I.save('/tmp/test.png')
7
If you need to serve it directly, you can save it to a string:
1 from cStringIO import StringIO
2
3 sb = StringIO()
4 I.save(sb, 'PNG')
5 s = sb.getvalue()
6
Pythonware PIL page: http://www.pythonware.com/products/pil/index.htm
(PIL in the Python wiki: http://wiki.python.org/moin/PythonImagingLibrary)