PIL处理PNG的问题

2024-04-20 13:25:39 发布

您现在位置:Python中文网/ 问答频道 /正文

from PIL import ImageFile as PILImageFile

p = PILImageFile.Parser()

#Parser the data
for chunk in content.chunks():
    p.feed(chunk)    
try:
    image = p.close()
except IOError:                        
    return None
#Here the model is RGBA
if image.mode != "RGB":
    image = image.convert("RGB")

它总是卡在这里:

^{pr2}$

Tags: theinfromimageimportparserfordata
1条回答
网友
1楼 · 发布于 2024-04-20 13:25:39

这是由于错误的close-within-PIL编码造成的,这是一个bug。在

编辑文件(系统上的路径可能不同):

sudo vi/usr/lib64/python2.6/site-packages/PIL/图像文件.py

在线283修改:

def close(self):
    self.data = self.offset = None

更改为:

^{pr2}$

就这样,注释掉损坏的代码,添加正确的行,并保存文件。一切都完成了,只要运行以前失败的程序,它现在就可以工作了。在

相关问题 更多 >