Resizing uploaded image in external method with Pil

Peter Sebrechts     [EMAIL PROTECTED]


I have a Form, where I can select an Image to upload, combined with
several fill-in fields for the Image-properties.

The Form starts with:
<form action="add_newImage_html" METHOD="POST"

The uploadfield is:
<input type="file" name="newimage" value="">

Next are the other input-fields and the Submit button.

The uploadform and the DTMLmethod 'add_newImage_html' reside in the
folder 'Images', where the new created image-objects are stored.
In each image-object is the uploaded newimage stored, and also a
subfolder,  where a new created thumbnail from the original image is
The resizing to a thumbnail is done in an external method with Pil.
And here is my problem:
I can pass an Image trough an external method without resizing it.
However,  when I try to open it with " im =",
I receive an errormessage: 'cannot identify image file'
After long searches in the Archives, I'm aware that it has something to
do with making the image-data available as a string or as a file-handle.
After many trials,  I've got only errors...

The dtml-method 'add_newImage_html' is as follows:

<dtml-with REQUEST>
   <dtml-if "newimage.filename">
      <dtml-call  "REQUEST.set('IDnr',REQUEST.form['new_ IDnr '])">
      <dtml-with "manage_addProduct['ImageProduct']">
         <dtml-call "Imageclass_add(_.None,_, NoRedir=1)">
      <dtml-in "objectValues(['Images'])">
         <dtml-if "(_['sequence-item'].id == REQUEST.form['new_ IDnr
            <dtml-call "REQUEST.set('new_ArtNo',_['sequence-item'])">
      <dtml-call "_['new_ IDnr
      <dtml-call "_['new_ IDnr '].manage_addFolder('preview')">
# until now, everything is OK:  image-object is created, image stored
and previewfolder created.

#now, I try to make a thumbnail and store it in the 'preview' folder:
      <dtml-with "_['new_ IDnr '].preview">

The external method 'thumbmaker':

def  thumbmaker (self,newimage):
 """convert image to preview-size (128 x 128) """
 import Pil
 im =
 im = im.thumbnail((128,128))
 return im

I tried also:
 im =     # (with StringIO imported)

and in the dtml-method:

and passing via REQUEST.newimage from the dtml- to the external method

and finally refering to the already stored image was also without

Ps:  I know that Photo does something similar,  but it seems me not easy
to combine with my multi-inputfield uploadForm.


Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to