[Image-SIG] PIL resize with aspect ratio?

Chris Cogdon chris at cogdon.org
Thu Jan 5 20:55:31 CET 2006


On Jan 5, 2006, at 11:49, Count László de Almásy wrote:

> Greetings,
>
> I'm new to PIL, and am wondering if the following is possible.
>
> I want to resize an image by only specifying the width, but not the
> height.  The height should be expanded or contracted automatically to
> fit the width value while maintaining the aspect ratio of the image.
>
> Second, I want to be able to specify the JPEG compression level.
>
> If you are familiar with ImageMagick, these would be accomplished
> using the following for example:
>
> % mogrify -quality 95 -resize 500x big.jpg
>
> I can't figure out whether these things are possible from the PIL
> documentation or not.  Any ideas?

i.thumbnail ( (128,128), Image.ANTIALIAS )

this will create a thumbnail that is no more than 128x128, but will 
keep the original geometry.


-- 
    ("`-/")_.-'"``-._        Chris Cogdon <chris at cogdon.org>
     . . `; -._    )-;-,_`)
    (v_,)'  _  )`-.\  ``-'
   _.- _..-_/ / ((.'
((,.-'   ((,/   fL



More information about the Image-SIG mailing list