Python Imaging: load jpeg from memory Python Imaging: load jpeg from memory python python

Python Imaging: load jpeg from memory


PIL's Image.open object accepts any file-like object. That means you can wrap your Image data on a StringIO object, and pass it to Image.Open

from io import BytesIOfile_jpgdata = BytesIO(jpgdata)dt = Image.open(file_jpgdata)

Or, try just passing self.rfile as an argument to Image.open - it might work just as well. (That is for Python 3 - for Python 2 use from cStringIO import StringIO as BytesIO)


Use StringIO so Image can access your data as if it were a file.