python - PIL Image.resize() not resizing the picture

ID : 131383

viewed : 7

Tags : pythonresizepython-imaging-librarypython

Top 4 Answer for python - PIL Image.resize() not resizing the picture

vote vote

93

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.

vote vote

81

[Update] ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.image.resize((100,100),Image.ANTIALIAS)

vote vote

80

Today you should use something like this:

from PIL import Image  img = Image.open(r"C:\test.png") img.show() img_resized = img.resize((100, 100), Image.Resampling.LANCZOS) img_resized.show() 
vote vote

65

Top 3 video Explaining python - PIL Image.resize() not resizing the picture

Related QUESTION?