[ZOPE] External Method process limits? bug fix!
missive at frontiernet.net
Tue Jul 17 10:43:26 CEST 2001
On 16 Jul 2001 18:23:13 -0700, ruckc <ruckc at yahoo.com> wrote:
> I tried this change, and i still only get a 15 byte Image Object in Zope.
Does the example work for you at all (ie for small images) or is it
completely broken? It is working fine for me now...
I never got any mangled Image Objects. Either it worked ok, or I
got a traceback saying that the type being passed to PIL
(or cStringIO, I was never quite sure) was not correct.
Is the created image.thumb.jpg a valid image?
> missive at frontiernet.net (Lee Harr) wrote:
>> 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