[Zope] PIL Question

J. Joy kyroraz@yahoo.com
Sun, 12 May 2002 00:41:18 -0700 (PDT)


--0-763491406-1021189278=:87591
Content-Type: text/plain; charset=us-ascii


 
  Ross Lazarus <do_not_reply_to_this@bellatlantic.net> wrote: the img tag expects the server to deliver an existing image file from 
somewhere. What you need to do is a little more complex (!). You COULD 
write the image into a zope object (bad idea for lots of reasons - eg 
zodb bloat) or to a localFS (better but still sucky) and deliver it from 
there using an img tag. AFAIK, this is the ONLY way to embed your image 
into a page with text and stuff.

I use PIL to make images and either email them or return them for the 
browser to display or to save. Email is good if the generation takes a 
long time obviously. To get the browser to display a returned image 
binary, you must set the mime type in the http headers to image/jpeg 
using or whatever and returning the binary image - the browser will 
display it correctly.

If you want the image to be saveable, it gets worse. IE and netscape are 
both broken if you try the file-disposition header, it doesn't work as 
advertised. There's a work around which I use - namely setting the mime 
type to application/octet-stream

> 
> I'm trying to create an external method that will take variables that exist in a ZSQL call and will output an image
> 
> based on that: 
> 
> import Image, ImageDraw, StringIO, os.path
> 
> def PILtest():
> image = Image.new('RGB',[25,25])
> ## IMage Stuff Happens here!
> return image
> 
> Where this would occur in a DTML-Method of:
> 
> 

>  
> 
> 
> But I can't get PILtest to output the image itself. Save() doesn't seem to be of help directly. Anyone have any suggestions?
> 
> Jason


-- 
Ross Lazarus
Visiting Associate Professor in Medicine,
Channing Labs, 181 Longwood Ave., Boston MA 02115, USA.
Fax:+617 525 0958, Office: +617 525 2730



---------------------------------
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
--0-763491406-1021189278=:87591
Content-Type: text/html; charset=us-ascii

<P> 
<P>&nbsp; <B><I>Ross Lazarus &lt;do_not_reply_to_this@bellatlantic.net&gt;</I></B> wrote: 
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">the img tag expects the server to deliver an existing image file from <BR>somewhere. What you need to do is a little more complex (!). You COULD <BR>write the image into a zope object (bad idea for lots of reasons - eg <BR>zodb bloat) or to a localFS (better but still sucky) and deliver it from <BR>there using an img tag. AFAIK, this is the ONLY way to embed your image <BR>into a page with text and stuff.<BR><BR>I use PIL to make images and either email them or return them for the <BR>browser to display or to save. Email is good if the generation takes a <BR>long time obviously. To get the browser to display a returned image <BR>binary, you must set the mime type in the http headers to image/jpeg <BR>using or whatever and returning the binary image - the browser will <BR>display it correctly.<BR><BR>If you want the image to be saveable, it gets worse. IE and netscape are <BR>both broken if you try the file-disposition header, it doesn't work as <BR>advertised. There's a work around which I use - namely setting the mime <BR>type to application/octet-stream<BR><BR>&gt; <BR>&gt; I'm trying to create an external method that will take variables that exist in a ZSQL call and will output an image<BR>&gt; <BR>&gt; based on that: <BR>&gt; <BR>&gt; import Image, ImageDraw, StringIO, os.path<BR>&gt; <BR>&gt; def PILtest():<BR>&gt; image = Image.new('RGB',[25,25])<BR>&gt; ## IMage Stuff Happens here!<BR>&gt; return image<BR>&gt; <BR>&gt; Where this would occur in a DTML-Method of:<BR>&gt; <BR>&gt; <DTML-IN SQL_COMMAND><BR>&gt; <IMG src="http://us.f149.mail.yahoo.com/ym/PILtest"> <!--vars to be passed in with this--><BR>&gt; </DTML-IN><BR>&gt; <BR>&gt; But I can't get PILtest to output the image itself. Save() doesn't seem to be of help directly. Anyone have any suggestions?<BR>&gt; <BR>&gt; Jason<BR><BR><BR>-- <BR>Ross Lazarus<BR>Visiting Associate Professor in Medicine,<BR>Channing Labs, 181 Longwood Ave., Boston MA 02115, USA.<BR>Fax:+617 525 0958, Office: +617 525 2730<BR></BLOCKQUOTE><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="http://rd.yahoo.com/welcome/*http://launch.yahoo.com">LAUNCH</a> - Your Yahoo! Music Experience
--0-763491406-1021189278=:87591--