Re: thumbnail.  Your code already uses it.
BTW  I think everyone uses Pillow now (drop in replacement for PIL with 
similar methods).  

On Sunday, 8 November 2020 at 19:54:58 UTC gaelpri...@gmail.com wrote:

> > An interesting routine, but I just use PIL's thumbnail() method.  Could 
> you explain the advantages of your routine? 
> I've no idea. I've followed an example years ago and I'm still working 
> like that.
>
> Can you post here and example of how do you use the PIL's thumbnail() 
> method?
> Il giorno sabato 7 novembre 2020 alle 23:35:43 UTC+1 snide...@gmail.com 
> ha scritto:
>
>>
>>
>> On Sunday, November 1, 2020 at 1:46:51 PM UTC-8, Gaël Princivalle wrote:
>>>
>>> I've found that in this function the upload folder was without a '/' at 
>>> the beginning.
>>> On Webfaction it was working fine, on Opalstack no.
>>>
>>> I think it's due more to the Web2py version than to the hosting.
>>> On Webfaction I've PIL (not Pillow) Python 2.7.5 with Web2py 2.14.6. and 
>>> it works fine.
>>> On Opalstack I've Pillow Python 2.7.5 with Web2py 2.20.4.
>>> Anyway I've updated 'upload/' to '/upload/' and it works.
>>> If it could be useful for someone else, as this SMARTHUMB function has 
>>> been shared here.
>>>
>>> def SMARTHUMB(image, box, fit=False, name="thumb"):
>>>     #Downsample the image.
>>>     #@param img: Image -  an Image-object
>>>     #@param box: tuple(x, y) - the bounding box of the result image
>>>     #@param fit: boolean - crop the image to fill the box
>>>     if image:
>>>         request = current.request
>>>         img = Image.open(request.folder +* 'uploads/'* + image)
>>>         #preresize image with factor 2, 4, 8 and fast algorithm
>>>         factor = 1
>>>         while img.size[0] / factor > 2 * box[0] and img.size[1] * 2 / 
>>> factor > 2 * box[1]:
>>>             factor *= 2
>>>         if factor > 1:
>>>             img.thumbnail((img.size[0] / factor, img.size[1] / factor), 
>>> Image.NEAREST)
>>>
>>>         #calculate the cropping box and get the cropped part
>>>         if fit:
>>>             x1 = y1 = 0
>>>             x2, y2 = img.size
>>>             wRatio = 1.0 * x2 / box[0]
>>>             hRatio = 1.0 * y2 / box[1]
>>>             if hRatio > wRatio:
>>>                 y1 = int(y2 / 2 - box[1] * wRatio / 2)
>>>                 y2 = int(y2 / 2 + box[1] * wRatio / 2)
>>>             else:
>>>                 x1 = int(x2 / 2 - box[0] * hRatio / 2)
>>>                 x2 = int(x2 / 2 + box[0] * hRatio / 2)
>>>             img = img.crop((x1, y1, x2, y2))
>>>
>>>         #Resize the image with best quality algorithm ANTI-ALIAS
>>>         img.thumbnail(box, Image.ANTIALIAS)
>>>
>>>         root, ext = os.path.splitext(image)
>>>         thumb = '%s_%s%s' % (root, name, ext)
>>>         img.save(request.folder +  *'uploads/'* + thumb)
>>>         return thumb
>>>
>>
>> An interesting routine, but I just use PIL's thumbnail() method.  Could 
>> you explain the advantages of your routine?
>>
>> /dps
>>  
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/b1688c63-e4c4-41ee-a584-43f1ae9d0cean%40googlegroups.com.

Reply via email to