The thumbnail
entry from the PIL docs specifically says it maintains the aspect ratio of the original. Try using resize
instead, it doesn't appear to maintain aspect ratio, at least from what I see.
Python: Resize Image to a fixed size, ignoring the initial aspect ratio
-
12-07-2023 - |
Question
I am trying to scale an incoming image which can be of (any type, any size) to a fixed grayscale image (eg 14x14). What I do is:
from PIL import Image
...
img = Image.open(args.picture).convert('L')
img.thumbnail( (14,14), Image.ANTIALIAS) #img.resize returns Non-Type
but this returns a 12x14 instead of 14x14, due to the original aspect ratio apparently.
How would I achieve a 14x14, for any possible input?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow