Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting error on resize img using pillow and python3.8

Here is my code.

from PIL import Image
imgwidth = 800
img = Image.open('img/2.jpeg')
concat = (imgwidth/img.size[0])
height = float(img.size[1])*float(concat)
img = img.resize((imgwidth,height), Image.ANTIALIAS)
img.save('output.jpg')

I found this example from a blog. I have run this code and got the bellow error, I am new in python and not understand the actual problem.

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/PIL/Image.py", line 1929, in resize
    return self._new(self.im.resize(size, resample, box))
TypeError: integer argument expected, got float

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

as img.resize() function expect integer value for height, so please make sure height should be an integer type.
Update your code with the below code, I hope it should be working for you.

from PIL import Image
imgwidth = 800
img = Image.open('img/2.jpeg')
concat = float(imgwidth/float(img.size[0]))
height = int((float(img.size[1])*float(concat)))
img = img.resize((imgwidth,height), Image.ANTIALIAS)
img.save('output.jpg')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading