Вопрос

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