Does Python PIL change proportions?

Does the PIL change the exact dimensions that I give them, no matter what? Or will he try to keep the aspect ratio if I give him something like the Image.ANTIALIAS argument?

+4
source share
3 answers

How to resize an image using PIL and keep its aspect ratio?

Image.resize from PIL will do exactly the same as said. Not behind the scenes.

+7
source

Yes, it will keep proportions using the sketch method:

 image = Image.open(source_path) image.thumbnail(size, Image.ANTIALIAS) image.save(dest_path, "JPEG") 
+12
source

Yes. The thumbnail () method is what is needed here ... One thing that was not mentioned in this or other related posts is that the "size" must be either a list or a tuple. Thus, to resize to a maximum size of 500 pixels, you would call: image.thumbnail ((500 500), Image.ANTIALIAS)

See also this entry on this topic: How do I resize an image using PIL and keep its aspect ratio?

+1
source

Source: https://habr.com/ru/post/1300814/


All Articles