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

Ausum Studio ausum_studio@hotmail.com
Tue, 19 Nov 2002 18:00:47 -0500


Dive into this product's code to get to know how to return the image object
from a PIL procedure.

http://www.zope.org/Members/bowerymarc/ImageTag_Hotfix


Ausum


----- Original Message -----
From: Sean K
To: zope@zope.org
Sent: Tuesday, November 19, 2002 5:43 PM
Subject: [Zope] Returning a pil generated image from a python product


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())

my index_html
<dtml-var standard_html_header>
<IMG src="./dynamicImage?RESPONSE=RESPONSE">
<dtml-var standard_html_footer>

the product class inherits Item, Persistent and Implicit
the dynamicImage method has an argument RESPONSE
When I click on view all I get is an image placeholder box (true as well
when using the same image tag in a dtml method in the root folder), however
from a dtml method in the root folder <dtml-var
expr="TestObject.dynamicImage(RESPONSE)"> will render an image as the only
content. any other content in the method is ignored.

This is my first attempt at a product, so after much hair pulling I must get
it to work.
Thank you in advance for any help
Sean K




Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site