我使用Pillow lib創建縮略圖。我創造了很多人,居然超過10000Python Pillow - ValueError:解壓縮數據太大
程序工作正常,但加工後的四圍1.500,我得到以下錯誤:
Traceback (most recent call last):
File "thumb.py", line 15, in <module>
im = Image.open('/Users/Marcel/images/07032017/' + infile)
File "/Users/Marcel/product-/PIL/Image.py", line 2339, in open
im = _open_core(fp, filename, prefix)
File "/Users/Marcel/product-/PIL/Image.py", line 2329, in _open_core
im = factory(fp, filename)
File "/Users/Marcel/product-/PIL/ImageFile.py", line 97, in __init__
self._open()
File "/Users/Marcel/product-/PIL/PngImagePlugin.py", line 538, in _open
s = self.png.call(cid, pos, length)
File "/Users/Marcel/product-/PIL/PngImagePlugin.py", line 136, in call
return getattr(self, "chunk_" + cid.decode('ascii'))(pos, length)
File "/Users/Marcel/product-/PIL/PngImagePlugin.py", line 319, in chunk_iCCP
icc_profile = _safe_zlib_decompress(s[i+2:])
File "/Users/Marcel/product-/PIL/PngImagePlugin.py", line 90, in _safe_zlib_decompress
raise ValueError("Decompressed Data Too Large")
ValueError: Decompressed Data Too Large
我的程序是非常簡單的:
import os, sys
import PIL
from PIL import Image
size = 235, 210
reviewedProductsList = open('products.txt', 'r')
reviewedProducts = reviewedProductsList.readlines()
t = map(lambda s: s.strip(), reviewedProducts)
print "Thumbs to create: '%s'" % len(reviewedProducts)
for infile in t:
outfile = infile
try:
im = Image.open('/Users/Marcel/images/07032017/' + infile)
im.thumbnail(size, Image.ANTIALIAS)
print "thumb created"
im.save('/Users/Marcel/product-/thumbs/' + outfile, "JPEG")
except IOError, e:
print "cannot create thumbnail for '%s'" % infile
print "error: '%s'" % e
我在本地MacBook Pro上執行此操作。
我不太清楚是什麼導致了這個錯誤,但是你總是可以添加第二個錯誤處理位來至少記錄哪些文件導致這個錯誤,並繼續執行你的列表,例如:''',除了ValueError,e:print「不能創建'%s'的縮略圖「%infile 」錯誤:' %s'「%e''' –
我不知道緩衝一下可能會阻止嗎?聽起來就像程序內存不足。你是否也確定它不會在同一點崩潰? – celestialroad
@celestialroad有趣的是,它對於第一批1500張照片來說工作得很好。我現在將測試來自James Kent的日誌選項,以查看更多 – Marcel