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

后端 未结 20 2261
-上瘾入骨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 02:49

    The following script creates nice thumbnails of all JPEG images preserving aspect ratios with 128x128 max resolution.

    from PIL import Image
    img = Image.open("D:\\Pictures\\John.jpg")
    img.thumbnail((680,680))
    img.save("D:\\Pictures\\John_resize.jpg")
    

提交回复
热议问题