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

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

    from PIL import Image
    from resizeimage import resizeimage
    
    def resize_file(in_file, out_file, size):
        with open(in_file) as fd:
            image = resizeimage.resize_thumbnail(Image.open(fd), size)
        image.save(out_file)
        image.close()
    
    resize_file('foo.tif', 'foo_small.jpg', (256, 256))
    

    I use this library:

    pip install python-resize-image
    

提交回复
热议问题