简体   繁体   中英

PIL resizing image

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?

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

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 (eg 10000) for height.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM