PIL + Zope + resizing images

KK pythonjob at op.pl
Mon Dec 6 05:18:32 EST 2004


Hallo.

I have Zope 2-7-0 on Linux platform and the following problem :)
I'm sending an image through form on the pythonScript. I want script to
resize image and save on the zope folder in 3 different size. OK, I use
ExternalMethod which uses PIL library to resize these images.

External method:
def xImageScale(img_file, maxx, maxy):
    from PIL import Image
    from cStringIO import StringIO
    im = Image.open(img_file)
    im.thumbnail((maxx, maxy), Image.ANTIALIAS)
    out_file_str = StringIO()
    im.save(out_file_str, im.format)
    out_file_str.seek(0)
    tmp=out_file_str.read()
    out_file_str.close()
    return tmp


pyrthonScript:
cAnimation = form.get('cAnimation','') # image from the form
if cAnimation:
         o.invokeFactory(id='cAnimationS.'+timeStamp, type_name='Image',
file=context.xImageScale(cAnimation, 100, 100)
         o.invokeFactory(id='cAnimationM.'+timeStamp, type_name='Image',
file=context.xImageScale(cAnimation, 200, 200)
         o.invokeFactory(id='cAnimationB.'+timeStamp, type_name='Image',
file=context.xImageScale(cAnimation, 300,300)


The result is "IOError,  cannot identify image file". So, when I want to
resize and save only one image it works properly.


Thanks in advance for any help
KK





More information about the Python-list mailing list