Open PIL image from byte file

The documentation for Image.open says that it can accept a file-like object, so you should be able to pass in a io.BytesIO object created from the bytes object containing the encoded image: from PIL import Image import io image_data = … # byte values of the image image = Image.open(io.BytesIO(image_data)) image.show()

PIL cannot identify image file for io.BytesIO object

(This solution is from the author himself. I have just moved it here.) SOLUTION: # This portion is part of my test code byteImgIO = io.BytesIO() byteImg = Image.open(“some/location/to/a/file/in/my/directories.png”) byteImg.save(byteImgIO, “PNG”) byteImgIO.seek(0) byteImg = byteImgIO.read() # Non test code dataBytesIO = io.BytesIO(byteImg) Image.open(dataBytesIO) The problem was with the way that Image.tobytes()was returning the byte object. … Read more