12
我试图创建一组缩略图,每个图像都是从原始图像中单独缩减的。PIL图像对象上的Python副本
image = Image.open(path)
image = image.crop((left, upper, right, lower))
for size in sizes:
temp = copy.copy(image)
temp.thumbnail((size, height), Image.ANTIALIAS)
temp.save('%s%s%s.%s' % (path, name, size, format), quality=95)
上面的代码似乎正常工作,但在测试我发现有些图像(我也说不清是什么特别之处他们,也许只为PNG)提出这个错误:
/usr/local/lib/python2.6/site-packages/PIL/PngImagePlugin.py in read(self=<PIL.PngImagePlugin.PngStream instance>)
line: s = self.fp.read(8)
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'read'
无copy()
这些图像工作得很好。
我可以为每个缩略图重新打开并裁剪图像,但我宁愿有一个更好的解决方案。
谢谢,这是有效的。 – Steffen