将MemoryFS filelike对象与PIL Imag一起使用

2024-09-26 22:54:58 发布

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

我试图用PIL打开PyFileSystem MemoryFS中的映像文件,我试图像这个例子一样这样做,但我得到了以下错误:

from PIL import Image
from fs.memoryfs import MemoryFS

fs=MemoryFS()
fs.makedir("test")
out=fs.open("test/file.jpg",'wb')
out.write(someimagefile.read())
out.close()
in=fs.open("test/file.jpg",'rb')
im=Image.open(in) #error: cannot identify image file <IO wrapper for <MemoryFile in <MemoryFS> test/file.jpg>>

但是,如果我不使用目录(例如out=fs.open("file.jpg",'wb')),它会按预期工作。

我做错什么了? 谢谢你的帮助。


Tags: infromtestimageimportpilopenout
1条回答
网友
1楼 · 发布于 2024-09-26 22:54:58

我已经收到一个错误使用以下行:

from fs.memoryfs import MemoryFS

可能我没有安装那个库。你需要这个图书馆吗?您只需打开图像而不必使用内存打开它:

^{pr2}$

旁注:我不会使用in作为变量名,因为它也是一个Python关键字。在

相关问题 更多 >

    热门问题