[Image-SIG] Help w/ resize
Fri, 26 May 2000 15:02:51 -0700
Basically, you just need to find out the aspect ratio of the new file at 275
pixels wide, and resize it using that size. It's pretty simple.
def BetterThumbnail(im, xmax, ymax):
inaspect =float(im.size)/ float(im.size)
outaspect = float(xmax) / float(ymax)
if inaspect > outaspect: # meaning that xmax will be used in resizing, and
y will be determined by aspect ratio
im = im.resize((xmax, int((float(xmax) / inaspect) + 0.5)),
Image.BICUBIC) # round it off, resize with Bicubic
else: # meaning that ymax will be used in resizing, and x will be
determined by aspect ratio
im = im.resize((int((float(ymax) * inaspect) + 0.5), ymax),
That should do it for ya... check it out with a couple test images though, it's
similar to what I use in my stuff, but not exactly the same.
Jason Long <email@example.com> on 05/15/2000 07:14:43 AM
cc: (bcc: Kevin Cazabon/cymbolic/gig)
Subject: [Image-SIG] Help w/ resize
Hi, I am a newbie to the PIL library and I need a little help.
For the record, I am using Python/PIL on Redhat 6.1 - Python version 1.5.2.
Here is my scenario: I have some images of all different sizes that I would
like to resize to a size of 275 pixels wide, and I don't care how tall. I want
to preserve the aspect ratio, though. I have had success with the thumbnail()
function, however the image quality is not very good. I was thinking that I
would get better results with resize() since I could specify BILINEAR or BICUBIC
filters. I guess I am not exactly sure how to use the resize function correctly
for my needs.
To summarize, I need to:
- resize images of different sizes to (275, x)
- generate the best quality I can
Basically, I'd like the thumbnail functionality with better output quality. I'm
sure I'm simply not doing something correctly. Perhaps a snipet of code would
do me best.
Thank you very much in advance.
Image-SIG maillist - Image-SIG@python.org