PIL: Thumbnail and end up with a square image

前端 未结 7 720
一个人的身影
一个人的身影 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:22

    Update of Cesar Canassa's answer.

    This will create a thumbnail of image.jpg as image_thumb.jpg:

    from PIL import Image, ImageOps
    fname = 'image.jpg'
    size = (48,48)
    thumb = ImageOps.fit(Image.open(fname), size, Image.ANTIALIAS)
    thumb.save('{}_thumb.jpg'.format(fname[:fname.rfind('.')]), "JPEG")
    
    0 讨论(0)
提交回复
热议问题