[Zope] System Error from Zope Book Example

Dan Shafer dan@gui.com
Mon, 18 Feb 2002 09:06:04 -0800


At 7:48 AM +0000 2/18/02, Chris Withers wrote:
>Dan Shafer wrote:
>>
>>     File /home/dshafer/Zope-2.3.3-src/Extensions/Thumbnail.py, line 16,
>>  in makeThumbnail
>
>Can you paste the code from Thumbnail.py here?
>
>(specifically, lines 10-20 ;-)

Sure. Sorry. I had done this in my original message and in an effort 
to conserve bandwidth I guess I made it harder for people to help.

Sigh.

Here's the code; I've eliminated the docstring so the first 
executable line in the function appears on line 10 of the original 
code.

def makeThumbnail(self, original_id, size=128)

	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(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 the thumbnail
	path, ext=os.path.splitext(original_id)
	thumbnail_id=path + '.thumb.jpg'

	#if there's an 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 'original_id' property
	thumbnail_image.manage_addProperty('original_id', 
original_id, 'string')


>cheers,
>
>Chris


-- 
Dan Shafer, Personal Creativity Trainer and Consultant
Trained Hartman Value Profile Analyst
http://www.danshafer.com/valueprofile.html