[Zope] (no subject)
Shane O'Sullivan
shane.osullivan@engitech.ie
Thu, 1 Nov 2001 15:25:30 -0000
This is a multi-part message in MIME format.
------=_NextPart_000_0012_01C162E9.7113A760
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by lxgate1.engitech.ie id PAA27560
Luis,
theres a problem with the thumbnails.py file in the zope book. It h=
as
to do with handling images over a certain size.
I've attached a correct version. You also have to have the PIL correctly
installed.
Regards,
Shane
----- Original Message -----
From: Luis Mart=EDn Arga=F1araz <skalivur@netscape.net>
To: <zope@zope.org>
Sent: Thursday, November 01, 2001 2:42 PM
Subject: [Zope] (no subject)
> hello.
> I=B4m a new Zope user and I have a problem whit the external methods. I=
=B4m
reading Zope Book (Chapter 8:"ScriptingZope.html") and I can=B4t add that=
the
external method "makeThumbnail", proposed there. It looks like zope doesn=
=B4t
recognize the variable "self".
> Any suggestion?
> Thanks
>
>
>
> __________________________________________________________________
> Your favorite stores, helpful shopping tools and great gift ideas.
Experience the convenience of buying online with Shop@Netscape!
http://shopnow.netscape.com/
>
> Get your own FREE, personal Netscape Mail account today at
http://webmail.netscape.com/
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
------=_NextPart_000_0012_01C162E9.7113A760
Content-Type: application/octet-stream;
name="Thumbnail.py"
Content-Disposition: attachment;
filename="Thumbnail.py"
Content-Transfer-Encoding: 7bit
def makeThumbnail(self, original_id, size=128):
"""
Makes a thumbnail image given an image Id when called on a Zope
folder.
The thumbnail is a Zope image object that is a small JPG
representation of the original image. The thumbnail has a
'original_id' property set to the id of the full size image
object.
"""
from PIL import Image
from cStringIO import StringIO
import os.path
# create a thumbnail image file
original_image=getattr(self, original_id)
original_file=StringIO(str(original_image.data)) # bug fix here
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 the thumbnail
path, ext=os.path.splitext(original_id)
thumbnail_id=path + '.thumb.jpg'
# if there's and old 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,
'thumbnail image')
thumbnail_image=getattr(self, thumbnail_id)
# set the 'originial_id' property
thumbnail_image.manage_addProperty('original_id',
original_id,
'string')
------=_NextPart_000_0012_01C162E9.7113A760--