简体   繁体   中英

PIL image conversion not using file system

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM