這是我的代碼。
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')
我從博客中找到了這個例子。我已經運行了這段代碼并得到了以下錯誤,我是 python 新手,不了解實際問題。
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
uj5u.com熱心網友回復:
作為img.resize()函式期望整數值height,所以請確保高度應該是整數型別。使用以下代碼更新您的代碼,我希望它對您有用。
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')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/350537.html
