you can store an error instead of filename with this code, you can get such
an error if zlib is not installed and you upload a png image

On Wed, Mar 30, 2011 at 9:30 PM, Anthony <[email protected]> wrote:

> That would make a nice slice. :)
>
> On Wednesday, March 30, 2011 1:55:52 PM UTC-4, pbreit wrote:
>
>> I don't totally understand the question but perhaps this will help. Below
>> is in my model which takes an image and then creates a thumbnail by passing
>> it to a function (also in the model).
>>
>>
>> db.define_table('item',
>>     Field('image', 'upload',
>> uploadfolder=request.folder+'static/uploads'),
>>      Field('image_thumb', 'upload',
>> uploadfolder=request.folder+'static/uploads',
>>             compute=lambda r: resize_image(r['image'], (150,130),
>> 'thumb')))
>>
>>  def resize_image(image, size, path):
>>     from PIL import Image
>>     import os.path
>>     try:
>>         img = Image.open('%sstatic/uploads/%s' % (request.folder, image))
>>         img.thumbnail(size, Image.NEAREST)
>>         root, ext = os.path.splitext(image)
>>         filename = '%s_%s%s' %(root, path, ext)
>>         img.save('%sstatic/uploads/%s' % (request.folder, filename))
>>     except Exception, e:
>>         return e
>>     else:
>>         return filename
>>
>

Reply via email to