1
votes

I am writing a script that changes the resolution of a floating point 2K (2048x2048) tiff image to 1024x1024.

But I get the following error:

File "C:\Python26\lib\site-packages\PIL\Image.py", line 1916, in open

IOError: cannot identify image file

My Code:

import Image

im = Image.open( inPath ) 
im = im.resize( (1024, 1024) , Image.ANTIALIAS )
im.save( outPath )

Any Ideas?

Download My Image From This Link

Also I'm using pil 1.1.6. The pil install is x64 same as the python install (2.6.6)

1

1 Answers

2
votes

Try one of these two:

  1. open the file in binary mode,
  2. give the full path to the file.

HTH!

EDIT after testing the OP's image:

It definitively seems like is the image having some problem. I'm on GNU/Linux and couldn't find a single program being able to handle it. Among the most informative about what the problem is have been GIMP:

GIMP error message

and ImageMagik:

display: roadnew_disp27-dm_u0_v0_hr.tif: invalid TIFF directory; tags are not sorted in ascending order. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/703.
display: roadnew_disp27-dm_u0_v0_hr.tif: unknown field with tag 18 (0x12) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/703.

I did not try it myself, but googling for "python tiff" returned the pylibtiff library, which - being specifically designed for TIFF files, it might perhaps offer some more power in processing this particular ones...

HTH!