Question

I'm using Python2.7.6 and Pillow 2.3.0 on 32 bits Windows. And I do not have PIL installed on my machine.

My problem is when I do following I get "cannot identify image file" error.

>>> from PIL import Image
>>> file = open(r"C:\\a.jpg", 'r')
>>> image = Image.open(file)
 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pillow-2.3.0-py2.7-win32.egg\PIL\Image.py", line 2025, in open
  IOError: cannot identify image file

But this works if I don't "Open" the file before opening it with Image.Open:

>>> image2 = Image.open(r"C:\\a.jpg", 'r')

NOTE: I cannot omit the "Open" statement.

Does anyone know what may be causing this strange behavior?

Thanks, in advance!

Was it helpful?

Solution

Don't do image = Image.open(file) , you already opened the file.

Try image = Image.open("C:\\a.jpg")

Here is the Image module: http://effbot.org/imagingbook/image.htm

EDIT:

Use 'rb' instea of 'r' when opening the file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top