How do I resize an image using PIL and maintain its aspect ratio?

后端 未结 20 2120
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:30

Is there an obvious way to do this that I\'m missing? I\'m just trying to make thumbnails.

20条回答
  •  别那么骄傲
    2020-11-22 03:05

    I also recommend using PIL's thumbnail method, because it removes all the ratio hassles from you.

    One important hint, though: Replace

    im.thumbnail(size)
    

    with

    im.thumbnail(size,Image.ANTIALIAS)
    

    by default, PIL uses the Image.NEAREST filter for resizing which results in good performance, but poor quality.

提交回复
热议问题