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
CodePudding user response:
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')