Here's what I have that works fine. All in the model file.
Field('image', 'upload', uploadfolder=request.folder+'static/uploads',
requires=IS_EMPTY_OR(IS_IMAGE())),
Field('image_thumb', 'upload',
uploadfolder=request.folder+'static/uploads',
readable=False, writable=False),
db.item.image_thumb.compute = lambda r: resize_image(r['image'], (150,130),
'thumb')
def resize_image(image, size, path, rotate=0):
if image:
try:
img = Image.open('%sstatic/uploads/%s' % (request.folder,
image))
img = img.convert("RGB") // not sure if this is necessary
img.thumbnail(size, Image.ANTIALIAS)
root, ext = os.path.splitext(image)
filename = '%s_%s%s' %(root, path, ext)
img.save('%sstatic/uploads/%s' % (request.folder, filename))
return filename
except Exception, e:
return e
else:
return None
PIL can be tricky to install. To verify that PIL is installed OK, run
python and:
>>> import PIL
>>> impost Image
>>> import _imaging