[Image-SIG] Aspect ratio in PIL

Markus Meyer meyer at mesw.de
Tue Mar 1 20:22:15 CET 2005


There are two ways to achieve this:

1. Calculate the aspect ratio yourself, then resize the picture 
accordingly, e.g. (not tested)

aspect_ratio = float(im.height) / im.width
im.resize(target_width, target_width  * aspect_ratio)

2. Use the thumbnail function. It creates an image with the given size, 
while padding the edges to preserve aspect ratio, when needed.


Markus

export at hope.cz schrieb:

>Is KEEP ASPECT RATIO available when I resize a picture?
>Thanks for help
>Lad.
>_______________________________________________
>Image-SIG maillist  -  Image-SIG at python.org
>http://mail.python.org/mailman/listinfo/image-sig
>
>  
>



More information about the Image-SIG mailing list