cherrypy.response.headers['Content-Type'] = 'image/png'
buffer = StringIO.StringIO()
surface.write_to_png(buffer)
buffer.seek(0)
return file_generator(buffer)
How to return an image in an HTTP response with CherryPy