PIL: Thumbnail and end up with a square image

前端 未结 7 762
一个人的身影
一个人的身影 2020-12-22 22:33

Calling

image = Image.open(data)
image.thumbnail((36,36), Image.NEAREST)

will maintain the aspect ratio. But I need to end up displaying th

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-22 23:19

    Why not simply use the resize method ?

    from PIL import Image
    image = Image.open('/path/to/img.png')
    image = image.resize((36,36), Image.ANTIALIAS)
    

    See recommendations for image resizing in this release note: https://pillow.readthedocs.io/en/stable/releasenotes/5.3.0.html

提交回复
热议问题