TypeError when resizing an image with PIL in Python -
note: self-answered question.
i'm trying resize image python code i'm getting following strange error:
traceback (most recent call last): file "resize.py", line 5, in <module> logo.save("startmyprojects_resized.png", format="png") file "/usr/lib/python2.7/dist-packages/pil/image.py", line 1439, in save save_handler(self, fp, filename) file "/usr/lib/python2.7/dist-packages/pil/pngimageplugin.py", line 572, in _save imagefile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)]) file "/usr/lib/python2.7/dist-packages/pil/imagefile.py", line 481, in _save e = image._getencoder(im.mode, e, a, im.encoderconfig) file "/usr/lib/python2.7/dist-packages/pil/image.py", line 399, in _getencoder return apply(encoder, (mode,) + args + extra) typeerror: integer required
and code i'm using is:
import image logo = image.open("my_image.png") logo = logo.resize((100, 100), image.antialias) logo.save("my_image_resized.png")
after research found this question on stackoverflow not same seems related.
@saranshmohapatra said had both pil , pillow installed (the same me) , solved problem uninstalling 1 of them. solved problem in different way.
i changed image
import.
from: import image
to: from pil import image
, fixed problem!
so final snipped looks this:
from pil import image logo = image.open("my_image.png") logo = logo.resize((100, 100), image.antialias) logo.save("my_image_resized.png")
Comments
Post a Comment