Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

python - PIL image.open() working for some images but not others

I use PIL to open AREA files from NOAA on a regular basis. In the last batch of images I received, the image.open() command simply does not work. Here is a simple code I wrote which yields the same results. It will open, rotate, and perform normal tasks with a file from a month ago, and not with a file from today.

from PIL import Image
im = Image.open("path/to/file")
im.show()

Here's the error:

File "image_goes.py", line 2, in <module>
im = Image.open("path/to/file")
File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file

Here's what I have tried:

  1. Opening the image on two separate machines.
  2. Changing the folder of the file in case there was a permission problem
  3. Redownloading the image, as well as two other batches, both using FTP manually AND our automatic script.

My hypothesis was that there was a problem with our downloading script and that it was not fully downloading the file, but that hypothesis is rejected by the fact that the new files are the correct size and that I manually downloaded them using an FTP client and got the same results.

My only other theory is that there is a problem with the NOAA files today or that they have been changed in such a way that PIL can no longer handle them, but I find that unlikely.

Any help greatly appreciated, Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Maybe be the content is not actually synced to the disk. try Image.open(open("path/to/file", 'rb'))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...