Reputation: 639
What's wrong with the following snippet?
It's not related to the image format, I tried both with jpg and png.
import Image
from cStringIO import StringIO
with open('/path/to/file/image.png') as f:
data = f.read()
img = Image.open(StringIO(data))
img.load()
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2030, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
EDIT:
This does happen with a randomly downloaded picture from the internet and the following most basic snippet:
import Image
im = Image.open('WicZW.jpg')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2030, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
Upvotes: 4
Views: 7407
Reputation: 1492
I solved this by using
from PIL import Image
instead of just doing
import Image
Upvotes: 3
Reputation: 639
The problem was in the mutual presence of the PIL and Pillow library on the machine:
# pip freeze | grep -E '(Pillow|PIL)'
PIL==1.1.7
Pillow==2.1.0
Upvotes: 3