Does Python PIL resize maintain the aspect ratio?

前端 未结 4 1508
南笙
南笙 2021-01-01 17:13

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

4条回答
  •  一向
    一向 (楼主)
    2021-01-01 17:33

    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.

提交回复
热议问题