Re: Spyce returning Images
"Andy Smith" <[email protected]> Thu, 9 Oct 2008 06:05:39 +0100
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
2008/10/8 T. Mohr <[email protected]>: > In PHP I used the GD library to create an image and return it as content > type "image/png" to the browser. > > Is there a simple way to do something similar using Spyce (maybe with > the PIL library)? Yes, you just need something like: response.setContentType("image/png") response.write(png_image_data) Where png_image_data contains the PNG file contents. To get this from PIL you can save your image to a StringIO buffer, eg: import StringIO buffer = StringIO.StringIO() image.save(buffer, "png") png_image_data = buffer.getvalue() buffer.close() PIL is a good image library and probably what I'd use, but there are alternatives. If you're familiar with GD you might find this binding easier (I haven't tried it myself): http://newcenturycomputers.net/projects/gdmodule.html Hope this helps, Andy ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/