[Zope-es] error con ejemplo de makethumbnail
Federico Manuel Echeverri Choux
echeverrifm en yahoo.com.ar
Jue Dic 21 05:50:58 CET 2006
Alexis Roda wrote:
> En/na Federico Manuel Echeverri Choux ha escrit:
>> Hola!! gente estoy estudiando los external method y me puse a hace el
>> ejemplo que hace un thumbnail, pero cuando le doy add al method me
>> dice esto:
>>
>> *Error Type: NameError*
>> *Error Value: name 'self' is not defined
>
> Utilizas self sin haberlo inicializado/declarado/definido previamente.
>
> Sin código que ver ni un traceback poco mas puedo decir.
>
>
>
>
> Saludos
> _______________________________________________
> Zope-es mailing list
> Zope-es en aditel.org
> http://listas.aditel.org/listinfo/zope-es
>
Este es el codigo que esta en el libro de zope
def makeThumbnail(self, original_id, size=200):
"""
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 an
'original_id' property set to the id of the full size image
object.
"""
import PIL
from StringIO import StringIO
import os.path
# none of the above imports would be allowed in Script (Python)!
# Note that PIL.Image objects expect to get and save data
# from the filesystem; so do Zope Images. We can get around
# this and do everything in memory by using StringIO.
# Get the original image data in memory.
original_image=getattr(self, original_id)
original_file=StringIO(str(original_image.data))
# create the thumbnail data in a new PIL Image.
image=PIL.Image.open(original_file)
image=image.convert('RGB')
image.thumbnail((size,size))
# get the thumbnail data in memory.
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 for the new thumbnail
self.manage_addProduct['OFSP'].manage_addImage(thumbnail_id,
thumbnail_file,
'thumbnail image')
# now find the new zope object so we can modify
# its properties.
thumbnail_image=getattr(self, thumbnail_id)
thumbnail_image.manage_addProperty('original_id', original_id, 'string')
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
Más información sobre la lista de distribución Zope-es