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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top