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  renders "".
>  > > How can I show the image?
> 
>  > Call its tag method.
> 
>  >
> 
> 
> Hi Paul,
> 
> how is the susi going? ;-)

Ah, I sold mine years ago. Nowadays I mostly just play bass. And you? :)
 
> I tried  but I get the 
> following error:
> ---
> Exception TypeTraversalError
> Exception Value   (, '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
> Instead of generating the image on the call to your ZPT you form an  src="/some/url/that/makes/my/image?foo=bar&baz=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:




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 )


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  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  src="/some/url/that/makes/my/image?foo=bar&baz=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
 """
 
 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":

Thumbnails
some other content...

  

  

some other content...


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-17 Thread Andrew Milton
+---[ Nico Grubert ]--
|  > > The  renders "".
|  > > How can I show the image?
| 
|  > Call its tag method.
| 
|  >
| 
| 
| Hi Paul,
| 
| how is the susi going? ;-)
| 
| I tried  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  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  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-17 Thread Nico Grubert
 > > The  renders "".
 > > How can I show the image?

 > Call its tag method.

 >


Hi Paul,

how is the susi going? ;-)

I tried  but I get the 
following error:
---
Exception Type  TraversalError
Exception Value (, '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__: (, 'tag')
 * Module zope.traversing.adapters, line 52, in traverse
   __traceback_info__: (, 
'tag', [])

TraversalError: (, 'tag')
---


However, I could not find any "tag" attribute in the lists of available 
attributes of the PIL.Image.Image instance. dir() 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-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.
>[,
> 
> ]
> 
> How can I display all images in a Zope page template?
> 
> I tried
> 
>
>
> 
> 
> The  renders "". How can I 
> show the image?

Call its tag method.



-- 

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 )


[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.
   [,

]

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

I tried

   


The  renders "". 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 )