Return a image instance from script
A very simple (?) problem: from a script I want to pass an image object to an external method. In Python:
def test(): ... foo=open('new.gif') ... return foo ... test() <open file 'new.gif', mode 'r' at 0x80df2e0>
In Zope: def test(): foo=open('new.gif') return foo This does not return an instance of the image but <img src="http://foo.bar.com" alt="" title="" height="10" width="10" border="0" /> Zope's doing some magic. How do I get the image object? Regards Christoph
Hi Christoph, Christoph Landwehr wrote:
A very simple (?) problem:
from a script I want to pass an image object to an external method.
In Python:
def test(): ... foo=open('new.gif') ... return foo ... test() <open file 'new.gif', mode 'r' at 0x80df2e0>
Thats not an Image object, its just a file object or rather its repr()
In Zope: def test(): foo=open('new.gif') return foo
I really doubt the open() part here.
This does not return an instance of the image but <img src="http://foo.bar.com" alt="" title="" height="10" width="10" border="0" />
Zope's doing some magic. How do I get the image object?
No, it just uses repr() here, which maps to the objects __str__ Method which happens to render a HTML tag for the image. if foo is an instance of zopes Image, foo has attributes like width, hight and so on - in short, its your image. It depends on what you want to do with it. Everything you need to know about these objects is in the Zopebooks API reference. Regards Tino
Hi Tino,
In Zope: def test(): foo=open('new.gif') return foo
I really doubt the open() part here.
You are absolutely right. It is: def test():
foo=container.new_gif return foo
No, it just uses repr() here, which maps to the objects __str__ Method which happens to render a HTML tag for the image.
It depends on what you want to do with it.
I want to pass a file object to an external method to use PIL. Since I can not use StringIO within Zope I need to pass an appropriate object to the external method and do the StringIO in the external method. Regards Christoph
Hi Christoph, Christoph Landwehr wrote: [...]
It depends on what you want to do with it.
I want to pass a file object to an external method to use PIL. Since I can not use StringIO within Zope I need to pass an appropriate object to the external method and do the StringIO in the external method.
Maybe you want to have a look at the Photo product. It already uses PIL or Imagemagick depending on configuration. I bet you can easy strip it down to whatever you want to do with it. Recent PIL does not even need StringIO and stuff. You can also pass in a string with image data. Regards Tino Wildenhain
participants (2)
-
Christoph Landwehr -
Tino Wildenhain