문제

I would like to do image conversion/rewriting with PIL just using RAM memory. I have the image in bytes in RAM and I would like to convert it to some other format or possibly the same. I know I can do it like saving it in on the file system with some name, but I would like to do it just using RAM without touching the file system. I haven't found any examples. Any help would be appreciated! Thanks!

도움이 되었습니까?

해결책

You can use a StringIO file object instead of a regular file as well with both PIL Image.open and Image.save

# somewhere earlier in the code:
# data = ...

from StringIO import StringIO
fd = StringIO(data)
image = Image.open(fd)
image.show()

There's also a frombuffer function

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top