[Zope] Resizing an Image with PIL via a Form Upload

Jonathan dev101 at magma.ca
Thu Feb 22 15:54:46 EST 2007


----- Original Message ----- 
From: "Tom Von Lahndorff" <tom at modscape.com>
To: <zope at zope.org>
Sent: Thursday, February 22, 2007 1:29 PM
Subject: [Zope] Resizing an Image with PIL via a Form Upload


>
> I'm trying to resize an image uploaded from a form using PIL. I got it to 
> work on an existing image but I can't seem to get it to work on an image 
> that's uploaded through the form. The ID of the file I'm trying to upload 
> is "DSCF0004.jpg". The form, script and traceback are listed below. Thanks 
> in advance.
>
> <form action="processed/imgSizer" method="post" 
> enctype="multipart.form-data">
> <input type="file" name="original_id"> <input type="submit" name="submit" 
> value=" Add ">
> </form>
>
> (imgSizer External Method)
> 1 def makeImages(self, original_id):
> 2 3    import PIL.Image
> 4    import PIL
> 5    from StringIO import StringIO
> 6    import os.path
> 7
> 8    original_image=getattr(self, original_id)
> 9    original_file=StringIO(str(original_image.data))

just a guess, but i don't think getattr is returning what you think it is 
returning.

The image has not been 'stored' anywhere yet, it is just a FileUpload 
instance.  To get at the information in this instance:

# the var name used in your form is misleading, it is not just the image id
fileName = self.REQUEST['original_id'].filename
fileData = self.REQUEST['original_id'].read()


hth

Jonathan 



More information about the Zope mailing list