Reputation: 41665
image.thumbnail((128, 128), Image.ANTIALIAS)
PIL sets the height of the new image to the size given(128 here) and calculate the width to keep the aspect ratio.
Is there a way to set width to 128 and let it calculate height to keep the aspect ratio?
Upvotes: 0
Views: 430
Reputation: 1039
well if all else fails, you can always just use python directly as the calculator:
width_ratio = image.size[0]/128.0
new_height = image.size[1]/width_ratio
Upvotes: 1
Reputation: 9764
According to the documentation thumbnail method:
Modifies the image to contain a thumbnail version of itself, no larger than the given size.
Try setting width to 128 and using a big number (e.g. 10000) for height.
Upvotes: 0