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

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

    Just updating this question with a more modern wrapper This library wraps Pillow (a fork of PIL) https://pypi.org/project/python-resize-image/

    Allowing you to do something like this :-

    from PIL import Image
    from resizeimage import resizeimage
    
    fd_img = open('test-image.jpeg', 'r')
    img = Image.open(fd_img)
    img = resizeimage.resize_width(img, 200)
    img.save('test-image-width.jpeg', img.format)
    fd_img.close()
    

    Heaps more examples in the above link.

提交回复
热议问题