我正在尝试从 Flask 应用程序表单保存 jpg 图像。下面的代码工作正常:
blob = request.files[canvas_key]
blob.stream.seek(0)
data = blob.stream.read()
string_io = cStringIO.StringIO(data)
string_io 的类型为 <cStringIO.StringI object at 0x10bf2bf10>
.
但是当我尝试时:Image.open(string_io)
,我收到此错误:IOError: cannot identify image file
.
使用stream.seek(0)
似乎可以解决 other people 的这个问题,但就我而言,还没有。
最佳答案
感谢@Mark,我将捕获的图像类型从 WebP 更改为 PNG。
关于python - PIL.Image.open() 给出 IOError : cannot identify image file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24024713/