Ste*_*fen 22 python copy python-imaging-library
我正在尝试创建一组缩略图,每个缩略图都与原始图像分开缩小.
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)
Run Code Online (Sandbox Code Playgroud)
上面的代码似乎工作正常,但在测试时我发现一些图像(我不知道它们有什么特别之处,可能仅针对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'
Run Code Online (Sandbox Code Playgroud)
没有copy()这些图像工作就好了.
我可以为每个缩略图重新打开并裁剪图像,但我宁愿有更好的解决方案.
Fer*_*yer 47
我想copy.copy()这对PIL Image课程不起作用.请尝试使用Image.copy(),因为它有一个原因:
image = Image.open(path)
image = image.crop((left, upper, right, lower))
for size in sizes:
temp = image.copy() # <-- Instead of copy.copy(image)
temp.thumbnail((size, height), Image.ANTIALIAS)
temp.save('%s%s%s.%s' % (path, name, size, format), quality=95)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29780 次 |
| 最近记录: |