[Zope] Problem converting PIL-generated Image objects to Photo 1.2.3 objects

Jonathan Cyr cyrj at cyr.info
Fri Jun 11 22:41:38 EDT 2004


Hello,

I am having a problem converting Image objects generated by PIL to 
Photo objects (rbickers' Photo & Photo Folder 1.23) in Zope 2.7.0.

The error I get is:

Error Type: AttributeError
Error Value: 'str' object has no attribute 'read'

I am uploading an image into Zope, I am using an External Method & PIL 
  to standardize the dimensions & format of the image.  The method is 
extremely similar to the example the the Zope Book example of External 
Methods & PIL Thumbnail script.  At this point, I'd like to take these 
homegenous image objects and convert them to Photo objects inside a 
PhotoFolder and take advantage of the render-on-the-fly sizes.  I'm 
using RBickers' script image2photo python script, and I get the above 
error.

Here's the code for the thumbnails, works fine, Images seem fine, work 
fine, but wont convert to Photo...

> def makeThumbnail (self, original_id,  original_title, size=150):
>     """
>     Makes a thumbnail image given an image ID when called on a Zope folder.
>     Modified for WeddingWeblog from code in the Zope Book, Ch10
> 
>     The thumbnail is a Zope image object that is a small JPG representation
>     of the original image
> 
>     """
> 
>     from PIL import Image
>     from StringIO import StringIO
>     import os.path
> 
>     #create a thumbnail image file
>     original_image=getattr(self, original_id)
>     original_file=StringIO(str(original_image.data))
>     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 thumbnail
>     path, ext=os.path.splitext(original_id)
>     thumbnail_id=path + '_' +str(size)
> 
>     # if there's an existing 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, title=original_title)
>     thumbnail_image=getattr(self, thumbnail_id)
> 

I'm using the Image2Photo script in the Photo/PhotoFolder support, 
pythonscript:

> for image in context.objectValues(['Image']):
>           context.manage_delObjects([image.getId(),], REQUEST=context.REQUEST)
>           context.manage_addProduct['Photo'].manage_addPhoto(image.getId(), image.title, image.data, REQUEST=context.REQUEST)

I'm not well versed in the object types here...

any ideas?

-Jon Cyr
cyrj at cyr.info



More information about the Zope mailing list