Here is how I've made thumbnails in the past with PIL:

from os.path import getsize
import Image

def thumb(form):

    try:
        filename=form.vars.image.filename

        zfile=form.vars.image_newfilename.split('.')
        thumbnail=zfile[0] + '.' + zfile[1] + '.' + zfile[2] +
'.thumbnail.' + zfile[3]
        ifile=request.folder + 'uploads/' + form.vars.image_newfilename
        thumb = Image.open(ifile)

        #print thumb.format, ' - ', thumb.size
        fdim=thumb.size
        fsz=getsize(ifile)

        if fsz > 1024:
            fsz=fsz/1024
            if fsz > 1024:
                fsz=round(fsz/1024.0,2)
                fsz=str(fsz)+' MB'
            else:
                fsz=str(fsz)+' KB'

        thumb.thumbnail((200,200), Image.ANTIALIAS)
        ofile=request.folder + 'uploads/'+thumbnail

        thumb.save(ofile)

        if request.vars.id:
            
thumbnail0=db(db.foto.id==request.vars.id).select(db.foto.thumbnail)[0].thumbnail
            if thumbnail0: unlink(request.folder + 'uploads/' + thumbnail0)
            
db(db.foto.id==request.vars.id).update(thumbnail=thumbnail,filename=filename,
filesize=fsz,
               fileformat=thumb.format, filedim=str(fdim[0])+'x'+str(fdim[1]))
        else:
            
db(db.foto.id==form.vars.id).update(thumbnail=thumbnail,filename=filename,
filesize=fsz,
               fileformat=thumb.format, filedim=str(fdim[0])+'x'+str(fdim[1]))
    except:
        try:
            if form.vars.image__delete== 'on':

thumbnail=db(db.foto.id==request.vars.id).select(db.foto.thumbnail)[0].thumbnail
                unlink(request.folder + 'uploads/' + thumbnail)
                db(db.foto.id==request.vars.id).update(thumbnail='',filename='')
        except:
            pass


-wes
On Fri, Feb 5, 2010 at 2:41 AM, Pepe <[email protected]> wrote:
> Hello!
>
> have somebody an example of image manipulation using PIL + web2py ??
>
> i need to create different versions of an image when i upload it
> (different sizes).
>
> thanks a lot!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "web2py-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/web2py?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to