[ZOPE] External Method process limits? bug fix!

Lee Harr missive at frontiernet.net
Tue Jul 17 04:43:26 EDT 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:
>> 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