[Image-SIG] PIL resize with aspect ratio?

Count László de Almásy calmasy at gmail.com
Thu Jan 5 21:17:49 CET 2006


Thanks.  How about setting the JPEG compression setting?

Conceptually what I'm trying to do is the following:

Take an image file of arbitrary size and of arbitrary width and height,
and rescale it to a width of exactly 500 and a height of whatever,
as long as the aspect ratio is preserved.  Additionally, the rescaled
image must be < 100kb in size, but I want to preserve as much
quality as possible.  My thought was that if I could specify the
JPEG compression ratio as I can with ImageMagick, I could start
at a high value and iteratively go lower and lower until a rescaled
image file is produced that is just under 100kb size.

On 1/5/06, Chris Cogdon <chris at cogdon.org> wrote:
>
> 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