PIL Image.resize() not resizing the picture

前端 未结 1 1158
死守一世寂寞
死守一世寂寞 2020-12-24 05:52

I have some strange problem with PIL not resizing the image.

from PIL import Image
img = Image.open(\'foo.jpg\')

width, height = img.size
ratio = floor(heig         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 06:28

    resize() returns a resized copy of an image. It doesn't modify the original. The correct way to use it is:

    from PIL import Image
    #...
    
    img = img.resize((150, newheight), Image.ANTIALIAS)
    

    source

    I think what you are looking for is the ImageOps.fit function. From PIL docs:

    ImageOps.fit(image, size, method, bleed, centering) => image

    Returns a sized and cropped version of the image, cropped to the requested aspect ratio and size. The size argument is the requested output size in pixels, given as a (width, height) tuple.

    0 讨论(0)
提交回复
热议问题