[ZOPE] External Method process limits? bug fix!

ruckc ruckc at yahoo.com
Tue Jul 17 03:23:13 CEST 2001


I tried this change, and i still only get a 15 byte Image Object in Zope.

missive at frontiernet.net (Lee Harr) wrote in message news:<9iicpa$9ju$1 at node21.cwnet.roc.gblx.net>...
> Hi:
> 
> Thanks for your help. I finally broke down and joined the zope mailing list.
> It was not so difficult, really, just fill out the form at:
> 
> http://lists.zope.org/mailman/listinfo/zope
> 
> and reply to the confirmation message that goes out to you.
> 
> 
> Turns out there is a bug in the PIL External Method example in the Zope
> Book. Once the image.data attribute gets to a certain size, it is no
> longer pushed around as a string, but gets wrapped up in its own 
> different kind of object. PIL or cStringIO was objecting to that.
> 
> The fix is to wrap image.data in str() to force stringiness.
> Here is the corrected code...
> 
> (mostly from http://www.zope.org/Members/michel/ZB/ScriptingZope.dtml)
> 
> 
> 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')



More information about the Python-list mailing list