Sounds like we need an IAL (image abstraction layer) besides the DAL

On Mon, Jun 29, 2009 at 9:03 PM, Hans Donner<[email protected]> wrote:
> Note: In order to use the Images API in your local environment you
> must first download and install PIL, the Python Imaging Library. PIL
> is not available on App Engine; it is only used as a stub for the
> Images API in your local environment. Only the transforms provided in
> the images API are available on App Engine.
>
> On Mon, Jun 29, 2009 at 9:02 PM, Hans Donner<[email protected]> wrote:
>> http://code.google.com/intl/nl-NL/appengine/docs/python/images/installingPIL.html
>>
>> On Mon, Jun 29, 2009 at 8:31 PM, mdipierro<[email protected]> wrote:
>>>
>>> It is not pure python it is a binary library. As far as I know none of
>>> them runs on GAE.
>>>
>>> On Jun 29, 1:23 pm, Joe  Barnhart <[email protected]> wrote:
>>>> Since PIL is all Python, do you suppose it's compatible with GAE?
>>>> That could give it a nod over ImageMagick in my mind.
>>>>
>>>> On Jun 29, 9:12 am, mdipierro <[email protected]> wrote:
>>>>
>>>> > Something like this could go in gluon.conrtib send me a patch when you
>>>> > have time.
>>>>
>>>> > On Jun 29, 10:39 am, cjparsons <[email protected]> wrote:
>>>>
>>>> > > I've had success with PIL to thumbnail uploaded images.
>>>>
>>>> > > In upload form handling:
>>>>
>>>> > >    if form.accepts(request.vars,session):
>>>> > >       if not form.vars.get("delete_this_record",False):
>>>> > >          response.flash = "image accepted"
>>>> > >          makeThumbnail(form.vars.id)
>>>> > >       else:
>>>> > >          response.flash = "image deleted"
>>>>
>>>> > > then the function to make the thumbnail. This might have less error
>>>> > > handling than you'd like. My images are in the db, the main image is
>>>> > > field 'image_blob' and the thumbnail, also a blob, 'thumbnail_data'.
>>>> > > If yours are in a file then the changes you'd need would actually make
>>>> > > the code simpler.
>>>>
>>>> > > THUMBNAILSIZE = 120
>>>>
>>>> > > def makeThumbnail(id):
>>>> > >    import Image
>>>> > >    import StringIO
>>>>
>>>> > >    imgRecord = db.images[id]
>>>> > >    if not imgRecord:
>>>> > >       return None
>>>> > >    imgData = Image.open(StringIO.StringIO
>>>> > > (imgRecord.image_blob)).convert("RGB")
>>>> > >    imgData.thumbnail((THUMBNAILSIZE,THUMBNAILSIZE),Image.ANTIALIAS)
>>>> > >    thumbFile = StringIO.StringIO()
>>>> > >    imgData.save(thumbFile,"JPEG")
>>>> > >    thumbFile.seek(0)
>>>> > >    imgRecord.update_record(thumbnail_data=thumbFile.read())
>>>> > >    db.commit()
>>>> > >    return True
>>>>
>>>> > > From memory, the above will shrink the picture so the largest
>>>> > > dimension is THUMBNAILSIZE, and the aspect ratio is maintained - the
>>>> > > shorter dimension may be less than THUMBNAILSIZE if the image wasn't
>>>> > > square.
>>>>
>>>> > > From a different iteration of my code, the following will always give
>>>> > > you a square of dimensions xy by xy, without distorting the image, but
>>>> > > will crop the image if it wasn't already square.
>>>>
>>>> > > def makeThumbnail(blob, xy):
>>>> > >    imgData = Image.open(StringIO.StringIO(blob)).convert("RGB")
>>>> > >    # make sure thumbnails are square by cropping original to a
>>>> > >    # square.
>>>> > >    # Find the longest side
>>>> > >    w,h = imgData.size
>>>> > >    if w >= h:
>>>> > >       voffset=0
>>>> > >       hoffset=(w-h)/2
>>>> > >       ex = h
>>>> > >    else:
>>>> > >       hoffset=0
>>>> > >       voffset=(h-w)/2
>>>> > >       ex = w
>>>> > >    imgData = imgData.transform((xy,xy),Image.EXTENT,
>>>> > > (hoffset,voffset,hoffset+ex,voffset+ex),Image.BICUBIC)
>>>> > >    thumbFile = StringIO.StringIO()
>>>> > >    imgData.save(thumbFile,"JPEG")
>>>> > >    thumbFile.seek(0)
>>>> > >    return thumbFile
>>>>
>>>> > > Sorry if the speed I'm writing my reply, or the inelegance of my
>>>> > > implementation makes this post less than helpful.
>>>>
>>>> > > Chris
>>> >>>
>>>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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