Problem converting PIL-generated Image objects to Photo 1.2.3 objects
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@cyr.info
Seems to be a problem with Photo's handling of manipulated Zope Image objects... I moved to a alternative, called VarImage 2.31, different but more powerful, escpecially for my needs. VarImage 2.31 is available at... http://www.anansispaceworks.com/ VarImage's author made note of handling this problem in 2.3, perhaps the Photo product is just getting old, and hasn't kept pace. Has some great features, axis-flipping, black & white, scaling, cropping, etc. Like I said, different, powerful, and without the error. -Jon Cyr cyrj@cyr.info Jonathan Cyr wrote:
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@cyr.info
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Tuesday 15 June 2004 01:37 pm, Jonathan Cyr wrote:
Seems to be a problem with Photo's handling of manipulated Zope Image objects... I moved to a alternative, called VarImage 2.31, different but more powerful, escpecially for my needs.
VarImage 2.31 is available at...
Also available at http://sourceforge.net/projects/narya-project You will probably also want the patch from Eric Pollman which is supposed to fix a number of bugs: http://eric.pollmann.net/items/2004/4/2004_04_29_varimage_optimization_updat... It's reported to greatly improve cache performance (by several times in some cases). This is probably going to be in VarImage 2.3.2 as soon as I get my test server back up to check it with. Cheers, Terry -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
participants (2)
-
Jonathan Cyr -
Terry Hancock