我正在编写将浮点2K(2048x2048)tiff图像的分辨率更改为1024x1024的脚本。

但我收到以下错误:

打开文件“ C:\ Python26 \ lib \ site-packages \ PIL \ Image.py”,行1916

IOError:无法识别图像文件

我的代码:

import Image

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


有任何想法吗?

Download My Image From This Link

另外我正在使用pil 1.1.6。 pil安装与python安装(2.6.6)相同x64

最佳答案

尝试以下两种方法之一:


以二进制模式打开文件,
给出文件的完整路径。


HTH!

测试OP的图片后进行编辑:

看起来像是图像确实有问题。我在GNU / Linux上,找不到能够处理它的单个程序。关于问题所在,最有参考价值的是GIMP:



和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.


我自己没有尝试过,但是谷歌搜索“ python tiff”返回了pylibtiff库,该库是专门为TIFF文件设计的,在处理这个特定文件时可能会提供更多功能……

HTH!

07-24 09:45
查看更多