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

Sean K getmejazzed@yahoo.com
Fri, 22 Nov 2002 01:47:38 -0800 (PST)


--0-1954118220-1037958458=:12196
Content-Type: text/plain; charset=us-ascii


Thanks for the responses, 
I have tinkered and am able to get the image out to the browser via the index_html of the product. 
When I try and access an instance from <dtm-var picture>(for example) in a dtml method however, the image doesn't make it to the browser while all the other content in the method does. 
Simplified code - product still inherits as bellow in original post. 
    def pict(self): 
        im=PIL.Image.new('RGB', (200, 200))
        draw = PIL.ImageDraw.Draw(im)
        draw.rectangle([0,0,0,0], fill =(0,0,0))
        RESPONSE.setHeader("Content-type", "image/gif")
        outFile = cStringIO.StringIO()
        im.save(outFile, 'gif')
        
        return outFile.getvalue()

complete index_html - 
<IMG src="../pict"> (contained in a subfolder of the product called dtml) 
I am guessing that the image is maybe destroyed before it makes it to the dtml method but am probobly completely wrong. 
Once again, thankyou in advance for your help 
Sean Kemplay 

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

 

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


---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-1954118220-1037958458=:12196
Content-Type: text/html; charset=us-ascii

<P>Thanks for the responses, 
<DIV id=message>
<P>I have tinkered and am able to get the image out to the browser via the index_html of the product. 
<P>When I try and access an instance from &lt;dtm-var picture&gt;(for example) in a dtml method&nbsp;however, the image doesn't make it to the browser while all the other content in the method does. 
<P>Simplified code - product still inherits as bellow in original post. 
<P>&nbsp;&nbsp;&nbsp; def pict(self): 
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; im=PIL.Image.new('RGB', (200, 200))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; draw = PIL.ImageDraw.Draw(im)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; draw.rectangle([0,0,0,0], fill =(0,0,0))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RESPONSE.setHeader("Content-type", "image/gif")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outFile = cStringIO.StringIO()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; im.save(outFile, 'gif')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return outFile.getvalue()<BR>
<P>complete index_html - 
<P>&lt;IMG src="../pict"&gt; (contained in a subfolder of the product called dtml) 
<P>I am guessing that the image is maybe destroyed before it makes it to the dtml method but am probobly completely wrong. 
<P>Once again, thankyou in advance for your help 
<P>Sean Kemplay&nbsp;</P>
<P>&nbsp;<B><I>Sean K &lt;getmejazzed@yahoo.com&gt;</I></B> wrote:</P></DIV>
<BLOCKQUOTE style="BORDER-LEFT: #1010ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">
<P>I am writing a product that returns an image generated by pil (unfortunately it doesn't): </P>
<P>Create image-</P>
<P>im = PIL.Image.new('RGB',(width,height))</P>
<P>it is then drawn-</P>
<P>draw = ImageDraw.Draw(im)</P>
<P>draw.rectangle([0,0,width,height], fill=(250,250,250)) etc etc etc</P>
<P>after it is ready to be sent out I "save" it -</P>
<P>pic = cStringIO.StringIO()<BR>im.save(pic, 'GIF')</P>
<P>and send it</P>
<P>&nbsp;pic.seek(0)<BR>&nbsp;RESPONSE.setHeader("Content-type", "image/gif")<BR>&nbsp;RESPONSE.write(pic.read())</P>
<P>&nbsp;</P>
<P>my index_html</P>
<P>&lt;dtml-var standard_html_header&gt;<BR>&lt;IMG src="./dynamicImage?RESPONSE=RESPONSE"&gt;<BR>&lt;dtml-var standard_html_footer&gt;</P>
<P>&nbsp;</P>
<P>the product class inherits Item, Persistent and Implicit</P>
<P>the dynamicImage&nbsp;method has an argument RESPONSE</P>
<P>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 &lt;dtml-var expr="TestObject.dynamicImage(RESPONSE)"&gt; will render an image as the only content. any other content in the method is ignored.<BR></P>
<P>This is my first attempt at a product, so after much hair pulling I must get it to work.</P>
<P>Thank you in advance for any help</P>
<P>Sean K</P>
<P><BR>
<HR SIZE=1>
Do you Yahoo!?<BR><A href="http://rd.yahoo.com/hosting/mailsig/*http://webhosting.yahoo.com">Yahoo! Web Hosting</A> - Let the expert host your site</BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-1954118220-1037958458=:12196--