[Zope] External Method limits
Lee Harr
missive@hotmail.com
Wed, 11 Jul 2001 20:03:04 -0000
>From: Dieter Maurer <dieter@handshake.de>
>
>Lee Harr writes:
> > I am working through the section of the Zope Book on External Methods
> > (chapter 8: Advanced Zope Scripting --
> > http://www.zope.org/Members/michel/ZB/ScriptingZope.dtml -- Secton:
>Using
> > External Methods)
> >
> > There is an example there which uses PIL that I am having some trouble
>with.
> > Whenever I try to use makeThumbnail on a file which is more than about
>60K I
> > get the following error:
> >
> >
> > Error Type: TypeError
> > Error Value: expected string, ImplicitAcquirerWrapper found
> > ...
> > File /usr/local/www/Zope/Extensions/Thumbnail.py, line 18, in
>makeThumbnail
> > (Object: Traversable)
> > TypeError: (see above)
>Seems you use "file.data".
>
>This is a string for small file sizes but an object for large ones.
>Use "str(file.data)", instead.
>
>
>Dieter
Dieter:
Thank you so much. Works like a charm now. Here is the corrected code:
def makeThumbnail(self, original_id, size=128):
"""
Makes a thumbnail image given an image Id when called on a Zope
folder.
The thumbnail is a Zope image object that is a small JPG
representation of the original image. The thumbnail has a
'original_id' property set to the id of the full size image
object.
"""
from PIL import Image
from cStringIO import StringIO
import os.path
# create a thumbnail image file
original_image=getattr(self, original_id)
original_file=StringIO(str(original_image.data)) # bug fix here
image=Image.open(original_file)
image=image.convert('RGB')
image.thumbnail((size,size))
thumbnail_file=StringIO()
image.save(thumbnail_file, "JPEG")
thumbnail_file.seek(0)
# create an id for the thumbnail
path, ext=os.path.splitext(original_id)
thumbnail_id=path + '.thumb.jpg'
# if there's and old thumbnail, delete it
if thumbnail_id in self.objectIds():
self.manage_delObjects(thumbnail_id)
# create the Zope image object
self.manage_addProduct['OFSP'].manage_addImage(thumbnail_id,
thumbnail_file, 'thumbnail image')
thumbnail_image=getattr(self, thumbnail_id)
# set the 'originial_id' property
thumbnail_image.manage_addProperty('original_id', original_id,
'string')
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.