Does Python PIL resize maintain the aspect ratio? Does Python PIL resize maintain the aspect ratio? python python

Does Python PIL resize maintain the 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.


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?