[Zope] Returning a pil generated image from a python product

Tino Wildenhain tino@wildenhain.de
Wed, 20 Nov 2002 01:21:59 +0100


Hi,


--On Dienstag, 19. November 2002 14:43 -0800 Sean K <getmejazzed@yahoo.com> 
wrote:

>
> I am writing a product that returns an image generated by pil
> (unfortunately it doesn't):
>
> Create image-
>
> im = PIL.Image.new('RGB',(width,height))
>
> it is then drawn-
>
> draw = ImageDraw.Draw(im)
>
> draw.rectangle([0,0,width,height], fill=(250,250,250)) etc etc etc
>
> after it is ready to be sent out I "save" it -
>
> pic = cStringIO.StringIO()
> im.save(pic, 'GIF')
>
> and send it
>
>  pic.seek(0)
>  RESPONSE.setHeader("Content-type", "image/gif")
>  RESPONSE.write(pic.read())
>
You dont need the step with StringIO - you see your RESPONSE object
has a write() method too.
In fact it acts like a open (for writing) file object.

If it does not work - did you think of right permissions?
And did you give a docstring to the index_html/__str__/__call__
method(s)?

Regards
Tino