我试图将用户提交的PNG图像转换为JPEG,但是当我试图保存图像时,我得到
<type 'exceptions.IndexError'>: string index out of range
我使用CGI在Apache中运行python脚本。当我在控制台中运行脚本时,它可以正常工作。在
这是密码。在
^{pr2}$错误发生在p.save()行上。我认为这是一个权限问题,但我甚至给了文件/目录777个权限,它仍然不能工作。在
编辑 这是save()调用之后的结果。在
/usr/lib/python2.7/dist-packages/PIL/Image.py in save(self=<PIL.PngImagePlugin.PngImageFile image mode=RGB size=512x512>, fp='../files/outfile.jpg', format='JPEG', **params={})
1434
1435 # may mutate self!
=> 1436 self.load()
1437
1438 self.encoderinfo = params
self = <PIL.PngImagePlugin.PngImageFile image mode=RGB size=512x512>, self.load = <bound method PngImageFile.load of <PIL.PngImagePlugin.PngImageFile image mode=RGB size=512x512>>
/usr/lib/python2.7/dist-packages/PIL/ImageFile.py in load(self=<PIL.PngImagePlugin.PngImageFile image mode=RGB size=512x512>)
204 break
205 else:
=> 206 raise IndexError(ie)
207
208 if not s: # truncated jpeg
builtin IndexError = <type 'exceptions.IndexError'>, ie = IndexError('string index out of range',)
我要自己回答,因为雨果没有回复。在
有一个名为LOAD_TRUNCATED_IMAGES的标志,默认设置为False。在
您必须转到/usr/lib/python2.7/dist-packages/PIL/图像文件.py并将其设置为真。在
相关问题 更多 >
编程相关推荐