我发现类似问题here,解决方案有效。但我不希望丢失/截断字节的灰色阴影。我更可能会理解这个问题的正当原因。
我的尝试:
from PIL import Image
in_file = open("/root/1735221450770222881.jpg", "rb")
data = in_file.read()
print len(data)
im = Image.open(StringIO.StringIO(data))
print type(im)
thumb_io = StringIO.StringIO()
try:
out = im.load()
except IOError as e:
pass
回溯:
追踪(最近一次通话): 文件“test_image.py”,第25行,in out = im.resize((3200,3200),Image.LANCZOS) 文件“/usr/lib64/python2.7/site-packages/PIL/Image.py”,第1557行,>调整大小
self.load() 文件“/usr/lib64/python2.7/site-packages/PIL/ImageFile.py”,第232行,>在加载 “(%d字节未处理)”%len(b)) IOError:图像文件被截断(14个字节未处理)
N.B。这不是一般问题。对于我的大多数图像,没有错误提升。最终,我想要调整图像的大小,因为有些图像会成功,有些图像会在底部添加灰色图层。