[Image-SIG] PIL resize with aspect ratio?

Count László de Almásy calmasy at gmail.com
Thu Jan 5 23:25:10 CET 2006


Thanks so much, I had missed the 'quality' attribute.  BTW, is
'ANTIALIAS' the best choice for what I want to do?  I noticed the
docs mention the following:

"The BILINEAR and BICUBIC filters use a fixed input environment, and
are best used for scale-preserving geometric transforms and upsamping"

which seems like it suits rescaling while maintaining aspect ratio as
I am doing.

On 1/5/06, Chris Cogdon <chris at cogdon.org> wrote:
>
> On Jan 5, 2006, at 12:17, Count László de Almásy wrote:
>
> > 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.
>
> The thumbnail command just creates the thumbnail image in memory, but
> doesn't 'compress' it yet. You do the compression when you save it as a
> particular format, and then you can set the compression. here's a more
> complete example:
>
> i = Image.open ( path )
> i.thumbnail ( (128,128), Image.ANTIALIAS )
> i.save ( thumb_path, quality=75 )
>
>
> --
>     ("`-/")_.-'"``-._        Chris Cogdon <chris at cogdon.org>
>      . . `; -._    )-;-,_`)
>     (v_,)'  _  )`-.\  ``-'
>    _.- _..-_/ / ((.'
> ((,.-'   ((,/   fL
>
>


More information about the Image-SIG mailing list