[ZOPE] External Method process limits? bug fix!
ruckc at yahoo.com
Mon Jul 16 21:23:13 EDT 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>...
> 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:
> 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
> 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
> 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.save(thumbnail_file, "JPEG")
> # 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():
> # create the Zope image object
> 'thumbnail image')
> thumbnail_image=getattr(self, thumbnail_id)
> # set the 'originial_id' property
More information about the Python-list