Does PIL resize to the exact dimensions I give it no matter what? Or will it try to keep the aspect ratio if I give it something like the Image.ANTIALIAS
argume
Yes. the thumbnail() method is what is needed here... One thing that hasn't been mentioned in this or other posts on the topic is that 'size' must be either a list or tuple. So, to resize to a maximum dimension of 500 pixels, you would call: image.thumbnail((500,500), Image.ANTIALIAS)
See also this post on the subject: How do I resize an image using PIL and maintain its aspect ratio?
Yes it will keep aspect ratio using thumbnail method:
image = Image.open(source_path)
image.thumbnail(size, Image.ANTIALIAS)
image.save(dest_path, "JPEG")
How do I resize an image using PIL and maintain its aspect ratio?
Image.resize from PIL will do exactly as told. No behind scenes aspect ratio stuff.
No, it does not. But you can do something like the following:
im = PIL.Image.open("email.jpg"))
width, height = im.size
im = im.resize((width//2, height//2))
Here the height and width are divided by the same number, keeping the same aspect ratio.