I like the module approach. I just put the function in my model file like 
this:

db.item.image_thumb.compute = lambda r: resize_image(r['image'], (150,130), 
'thumb')
db.item.image_display.compute = lambda r: resize_image(r['image'], 
(320,320), 'display')

def resize_image(image, size, path, rotate=0):
    if image:
        try:
            img = Image.open('%sstatic/uploads/%s' % (request.folder, 
image))
            img = img.convert("RGB")
            img.thumbnail(size, Image.ANTIALIAS)
            img = img.rotate(rotate)
            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

Reply via email to