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:
<dtml-in SQL_COMMAND> <img src="PILtest"> <!--vars to be passed in with this--> </dtml-in>
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
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
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. This is not a problem. In the HTML example of how this is called, I may not have shown clearly enough that what I want to do is have the src be an object in the same folder that would generate this image upon calling it and the external python method would generate and return the image back. The part that I am having trouble with is with the return part of my external method. I do not know how to make it return the data of the image that was just generated. I can save it to a file, but I can't find a nice way of returning the image data back from the call. I searched for a few hours to try to find some practical examples of perhaps how to do this on google, but nothing came up. To wit, the External Call should act like a image when referenced, it's just having "stuff" passed to it to form the image in question. :) The External Call would be called like: <img src="MakeImage"> Where MakeImage would be the External Method.
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
--------------------------------- Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience
Ah. I see. To solve this, I made this very simple fakefile object: class FakeFile: ''' memory map equivalent of a real file ''' def __init__(self): self.contents = [] def write(self,s): self.contents.append(s) def read(self): return string.join(self.contents,'') and I tell PIL to write to it - the write method takes any file like object - as long as it has a write method. The code (where ldp is a PIL canvas) sort of looks like: fakef = FakeFile() ldp.writeimage(fakef,'jpeg') I then return fakef.read() from my external method as the binary image. Does that help? When you've finished, please write this up as a howto if you have time? cheers.. J. Joy wrote:
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.
This is not a problem. In the HTML example of how this is called, I may not have shown clearly enough that what I want to do is have the src be an object in the same folder that would generate this image upon calling it and the external python method would generate and return the image back. The part that I am having trouble with is with the return part of my external method. I do not know how to make it return the data of the image that was just generated. I can save it to a file, but I can't find a nice way of returning the image data back from the call. I searched for a few hours to try to find some practical examples of perhaps how to do this on google, but nothing came up.
To wit, the External Call should act like a image when referenced, it's just having "stuff" passed to it to form the image in question. :)
The External Call would be called like:
<img src="MakeImage">
Where MakeImage would be the External Method.
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:
<http://us.f149.mail.yahoo.com/ym/PILtest>
But I can't get PILtest to output the image itself. Save() doesn't
seem to be of help directly. Anyone have any suggestions?
Thanks :) And considering the lack of material based on this information, I'd be happy to make a brief how-to on this matter. :) Jason --- foohbah <foohbah@netscape.net> wrote:
Ah. I see. To solve this, I made this very simple fakefile object:
class FakeFile: ''' memory map equivalent of a real file ''' def __init__(self): self.contents = []
def write(self,s): self.contents.append(s)
def read(self): return string.join(self.contents,'')
and I tell PIL to write to it - the write method takes any file like object - as long as it has a write method. The code (where ldp is a PIL canvas) sort of looks like:
fakef = FakeFile() ldp.writeimage(fakef,'jpeg')
I then return fakef.read() from my external method as the binary image.
Does that help?
When you've finished, please write this up as a howto if you have time?
cheers..
J. Joy wrote:
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.
This is not a problem. In the HTML example of how this is called, I may not have shown clearly enough that what I want to do is have the src be an object in the same folder that would generate this image upon calling it and the external python method would generate and return the image back. The part that I am having trouble with is with the return part of my external method. I do not know how to make it return the data of the image that was just generated. I can save it to a file, but I can't find a nice way of returning the image data back from the call. I searched for a few hours to try to find some practical examples of perhaps how to do this on google, but nothing came up.
To wit, the External Call should act like a image when referenced, it's just having "stuff" passed to it to form the image in question. :)
The External Call would be called like:
<img src="MakeImage">
Where MakeImage would be the External Method.
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:
<http://us.f149.mail.yahoo.com/ym/PILtest>
But I can't get PILtest to output the image itself. Save() doesn't
seem to be of help directly. Anyone have any suggestions?
__________________________________________________ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com
participants (3)
-
foohbah -
J. Joy -
Ross Lazarus