I think you want a resize validator that resizes a file as it is
uploaded. this should do it but I let you do the debugging. ;-)

class RESIZE:
     def __init__(self,nx=32,ny=32,error_message='not an image'):
        (self.nx,self.ny,self.error_message)=(nx,ny,error_message)
     def __call__(self,value):
          import google.appengine.api as api
          import cStringIO
          try:
              avatar = api.images.resize(value.file.read(), self.nx,
self.ny)
              value.file = cStringIO.StringIO(avatar)
              return (value,None)
          except:
              return (value,self.error_message)

db.define_table('auth_user',...SQLField
('avatar','upload',requires=RESIZE()))



On May 12, 8:50 pm, Tito Garrido <titogarr...@gmail.com> wrote:
> Cool... I'm wondering how can I use that resize function on web2py...
>
>
>
> On Tue, May 12, 2009 at 10:45 PM, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > and this
>
> > class Image (webapp.RequestHandler):
> >  def get(self):
> >    greeting = db.get(self.request.get("img_id"))
> >    if greeting.avatar:
> >      self.response.headers['Content-Type'] = "image/png"
> >      self.response.out.write(greeting.avatar)
> >    else:
> >      self.error(404)
>
> > of course is all done by web2py automatically by
>
> >    def download(): return response.download(request,db)
>
> > Actually web2py is much more sophisticated that that since is handles
> > encoding/decoding of original filename, sets content-disposition too,
> > and if available can serve range/partial-content/if-modified-since
> > requests.
>
> > Massimo
>
> > On May 12, 8:41 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > > This
>
> > >   avatar = db.BlobProperty()
>
> > > is done transparently by web2py
>
> > >    db.define_table('user',SQLField('avatar','upload'))
>
> > > This
>
> > >    from google.appengine.api import images
>
> > > is useful and I did not know about it.
>
> > > Massimo
>
> > > On May 12, 8:31 pm, Tito Garrido <titogarr...@gmail.com> wrote:
>
> > > > Seems that it has a kind of Image support:
> >http://code.google.com/intl/pt-BR/appengine/docs/python/images/usingi...
>
> > > > On Tue, May 12, 2009 at 10:28 PM, mdipierro <mdipie...@cs.depaul.edu>
> > wrote:
>
> > > > > This is about installing PIL locally and that is easy.
> > > > > Does it mean that it is already available on GAE?
> > > > > I do not know.
>
> > > > > On May 12, 8:17 pm, Tito Garrido <titogarr...@gmail.com> wrote:
> > > > > > I could find this regarding PIL + GAE:
>
> >http://code.google.com/appengine/docs/python/images/installingPIL.html
>
> > > > > > But I don't know how could I resize the picture during the
> > upload...
>
> > > > > > On Tue, May 12, 2009 at 9:42 PM, mdipierro <
> > mdipie...@cs.depaul.edu>
> > > > > wrote:
>
> > > > > > > PIL includes binary modules. If GAE does not provide it already
> > (and I
> > > > > > > do not know if they do) there is no way to install it on GAE.
>
> > > > > > > On May 12, 7:12 pm, Tito Garrido <titogarr...@gmail.com> wrote:
> > > > > > > > Is there a way to use PIL on web2py+GAE? I mean, could we
> > reduce a
> > > > > > > picture
> > > > > > > > while we're uploading it to GAE?
>
> > > > > > > > Thanks in advance,
>
> > > > > > > > Tito
>
> > > > > > > > --
> > > > > > > > Linux User #387870
> > > > > > > > .........____
> > > > > > > > .... _/_õ|__|
> > > > > > > > ..º[ .-.___.-._| . . . .
> > > > > > > > .__( o)__( o).:_______
>
> > > > > > --
> > > > > > Linux User #387870
> > > > > > .........____
> > > > > > .... _/_õ|__|
> > > > > > ..º[ .-.___.-._| . . . .
> > > > > > .__( o)__( o).:_______
>
> > > > --
> > > > Linux User #387870
> > > > .........____
> > > > .... _/_õ|__|
> > > > ..º[ .-.___.-._| . . . .
> > > > .__( o)__( o).:_______
>
> --
> Linux User #387870
> .........____
> .... _/_õ|__|
> ..º[ .-.___.-._| . . . .
> .__( o)__( o).:_______
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to