Don't use readlines()
, it returns a list of strings which is not what you want. To retrieve the bytes from the file, use read()
function instead.
Your example worked out of the box with read()
and a JPG
file on my PC:
# Python 2.x
>>>from StringIO import StringIO
# Python 3.x
>>>from io import StringIO
>>>from PIL import Image
>>>image_file = StringIO(open("test.jpg",'rb').read())
>>>im = Image.open(image_file)
>>>print im.size, im.mode
(2121, 3508) RGB