本文介绍了错误Python成像库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Python Imaging Library进行化身变更系统,但是我遇到了以下错误的问题:
I'm doing a system of change of avatar using the Python Imaging Library, but I'm having problem in following error presented:
client.changeAvatar(data)
File "C:\Users\Administrator\Desktop\Main.py", line 332, in changeAvatar
iM = i.resize((100, 100), Image.ANTIALIAS)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1262, in resize
self.load()
File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 192, in load
raise IOError("image file is truncated (%d bytes not processed)" % len(b))
exceptions.IOError: image file is truncated (13 bytes not processed)
代码:
with open("%i.jpg" %(self.playerID), "wb") as f:
f.write(data)
i = Image.open("%i.jpg" %(self.playerID))
iM = i.resize((100, 100), Image.ANTIALIAS)
iM.save("%i.jpg" %(self.playerID))
im = i.resize((50, 50), Image.ANTIALIAS)
im.save("%i_50.jpg" %(self.playerID))
F = ftplib.FTP("", "", "")
cdTree("/public_html/avatar/%s"%(self.playerID))
for name in ["%i.jpg" %(self.playerID), "%i_50.jpg" %(self.playerID)]:
with open(name, "rb") as fp:
F.storbinary("STOR public_html/avatar/%s/%s" %(self.playerID, name), fp)
os.system("del %s" %(name))
F.quit()
有人可以帮我解决这个错误吗?
Can anyone help me solve this error?
推荐答案
一旦你有图像
object,重新使用它来制作不同的缩略图。
Once you have your Image
object, re-use it to make the different thumbnails.
看看函数,它比使用原始图像的下采样更容易使用。
Take a look at the Image.thumbnail() function, it's a little easier to use than just downsampling the original image.
import PIL, PIL.Image
from StringIO import StringIO
data = open('rose.jpg').read()
img = PIL.Image.open( StringIO(data) )
playerID = 123
# write full image to file
with open("%i.jpg" %(playerID), "wb") as f:
f.write(data)
# using same image, make 100px thumbnail
# TODO: use .thumbnail()
img.resize((100, 100), PIL.Image.ANTIALIAS
).save('%i_100.jpg' % playerID)
# make a 50px thumbnail
img.resize((50, 50), PIL.Image.ANTIALIAS
).save("%i_50.jpg" %playerID)
这篇关于错误Python成像库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!