Re: [Zope] Displaying PIL Images in Zope Templates

2008-09-19 Thread Paul Winkler
On Thu, Sep 18, 2008 at 08:22:37AM +0200, Nico Grubert wrote:
The span renders PIL.Image.Image instance at 0x23b97500.
How can I show the image?
 
   Call its tag method.
 
  span tal:replace=structure item/tag /
 
 
 Hi Paul,
 
 how is the susi going? ;-)

Ah, I sold mine years ago. Nowadays I mostly just play bass. And you? :)
 
 I tried span tal:replace=structure item/tag / but I get the 
 following error:
 ---
 Exception TypeTraversalError
 Exception Value   (PIL.Image.Image instance at 0x18e84ad0, 'tag')

Whoops, sorry, I didn't realize these were PIL images, I thought they
were OFS.Image or some such. But I see you already got the solution.

- PW
 

-- 

Paul Winkler
http://www.slinkp.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Displaying PIL Images in Zope Templates

2008-09-18 Thread Nico Grubert
   The span renders PIL.Image.Image instance at 0x23b97500.
   How can I show the image?

  Call its tag method.

 span tal:replace=structure item/tag /


Hi Paul,

how is the susi going? ;-)

I tried span tal:replace=structure item/tag / but I get the 
following error:
---
Exception Type  TraversalError
Exception Value (PIL.Image.Image instance at 0x18e84ad0, 'tag')

 *  Module Products.PageTemplates.Expressions, line 153, in _eval
 * Module zope.tales.expressions, line 124, in _eval
 * Module Products.PageTemplates.Expressions, line 83, in 
boboAwareZopeTraverse
 * Module zope.traversing.adapters, line 164, in traversePathElement
   __traceback_info__: (PIL.Image.Image instance at 0x18e84ad0, 'tag')
 * Module zope.traversing.adapters, line 52, in traverse
   __traceback_info__: (PIL.Image.Image instance at 0x18e84ad0, 
'tag', [])

TraversalError: (PIL.Image.Image instance at 0x18e84ad0, 'tag')
---


However, I could not find any tag attribute in the lists of available 
attributes of the PIL.Image.Image instance. dir(PIL_object) returns:
['_Image__transformer', '__doc__', '__getattr__', '__init__', 
'__module__', '_copy', '_dump', '_expand', '_makeself', '_new', 
'category', 'convert', 'copy', 'crop', 'draft', 'encoderconfig', 
'encoderinfo', 'filter', 'format', 'format_description', 'fromstring', 
'getbands', 'getbbox', 'getcolors', 'getdata', 'getextrema', 'getim', 
'getpalette', 'getpixel', 'getprojection', 'histogram', 'im', 'info', 
'load', 'mode', 'offset', 'palette', 'paste', 'point', 'putalpha', 
'putdata', 'putpalette', 'putpixel', 'quantize', 'readonly', 'resize',
'rotate', 'save', 'seek', 'show', 'size', 'split', 'tell', 'thumbnail', 
'tobitmap', 'tostring', 'transform', 'transpose', 'verify']

No tag method there... :-(


Regards
Nico
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Displaying PIL Images in Zope Templates

2008-09-18 Thread Andrew Milton
+---[ Nico Grubert ]--
|The span renders PIL.Image.Image instance at 0x23b97500.
|How can I show the image?
| 
|   Call its tag method.
| 
|  span tal:replace=structure item/tag /
| 
| 
| Hi Paul,
| 
| how is the susi going? ;-)
| 
| I tried span tal:replace=structure item/tag / but I get the 
| following error:

You can't do this

What you need to do is associate the image with a URL so it gets
generated when the browser processes the img tag.. UNLESS it's very small
in which case you can use the src=... attribute to contain the data.

So a PIL image should be returned by a script or external method that
you can browse to. Headers such as Content-Type should be set to set the
image type.

Instead of generating the image on the call to your ZPT you form an img
src=/some/url/that/makes/my/image?foo=barbaz=bat e.g. in order to
generate the right image.

-- 
Andrew Milton
[EMAIL PROTECTED]
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Displaying PIL Images in Zope Templates

2008-09-18 Thread Nico Grubert
 You can't do this
 
 What you need to do is associate the image with a URL so it gets
 generated when the browser processes the img tag.. UNLESS it's very small
 in which case you can use the src=... attribute to contain the data.
 
 So a PIL image should be returned by a script or external method that
 you can browse to. Headers such as Content-Type should be set to set the
 image type.
 
 Instead of generating the image on the call to your ZPT you form an img
 src=/some/url/that/makes/my/image?foo=barbaz=bat e.g. in order to
 generate the right image.

Hi Andrew

thank you for your answer.
I tried this but calling the page template only shows the image and the 
other content is not shown. I guess, it has something to do with the 
REQUEST.RESPONSE.setHeader('Content-Type', WEB_FORMAT) I set in the 
external method.

Here is the code I use:

External method createThumbnail:
--
def createThumbnail(self, photo):
  create PIL image
 
 snip
 thumb_data = StringIO()
 # 'thumb' is a PIL.Image.Image instance
 thumb.save(thumb_data, 'JPEG')

 REQUEST = self.REQUEST
 REQUEST.RESPONSE.setHeader('Content-Type', 'JPEG')
 return REQUEST.RESPONSE.write(thumb_data.getvalue())


Page Template thumbnails.html:

h1Thumbnails/h1
psome other content.../p
tal:rep tal:repeat=photo photos
  a tal:attributes=href photo/absolute_url;
img tal:attributes=src python: container.createThumbnail(photo) /
  /a
/tal:rep
psome other content.../p


In the page templates I iterate over a list of image objects (photos) 
and pass a single image object to external method.
As I mentioned above, this only shows the first image and not the other 
content nor the other images.

Did I miss something?

Regards
Nico
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Displaying PIL Images in Zope Templates

2008-09-18 Thread Nico Grubert
 Instead of generating the image on the call to your ZPT you form an img
 src=/some/url/that/makes/my/image?foo=barbaz=bat e.g. in order to
 generate the right image.

Got it. The magic is not to call the external method by 
container.createThumbnail() but use absolute URL to the external method. 
In the page template I have to use:

img tal:attributes=src 
string:${container/absolute_url}/createThumbnail?imagepath=${imgpath}/


Thanks for pointing me in the right direction.


Regards
Nico


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Displaying PIL Images in Zope Templates

2008-09-17 Thread Nico Grubert
Hi there

Is it possible to show several PIL.Image.Image instances in a Zope Page 
without creating a temporary Zope image object?

I have an external method that creates a list of
PIL.Image.Image instances, e.g.
   [PIL.Image.Image instance at 0x711fc60,
PIL.Image.Image instance at 0x711fc70
]

How can I display all images in a Zope page template?

I tried
tal:rep tal:repeat=item
   span tal:replace=item /
/tal:rep

The span renders PIL.Image.Image instance at 0x23b97500. How can I 
show the image?


Thanks in advance
Nico
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Displaying PIL Images in Zope Templates

2008-09-17 Thread Paul Winkler
On Wed, Sep 17, 2008 at 03:01:55PM +0200, Nico Grubert wrote:
 Hi there
 
 Is it possible to show several PIL.Image.Image instances in a Zope Page 
 without creating a temporary Zope image object?
 
 I have an external method that creates a list of
 PIL.Image.Image instances, e.g.
[PIL.Image.Image instance at 0x711fc60,
 PIL.Image.Image instance at 0x711fc70
 ]
 
 How can I display all images in a Zope page template?
 
 I tried
 tal:rep tal:repeat=item
span tal:replace=item /

 /tal:rep
 
 The span renders PIL.Image.Image instance at 0x23b97500. How can I 
 show the image?

Call its tag method.

span tal:replace=structure item/tag /

-- 

Paul Winkler
http://www.slinkp.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )