如何调试“OSError:9”通过libtiff和枕头保存tiff?

2024-06-26 09:15:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个TIFF文件,我不能用枕头处理。我知道pillow是libtiff的用户,但错误消息不足以调试问题:

image = PIL.Image.open(open("input.tif", "rb"))
image.save("out.tiff")

我立即得到以下(截断的)回溯:

PIL/Image.py in _ensure_mutable(self)
    616     def _ensure_mutable(self):
    617         if self.readonly:
--> 618             self._copy()
    619         else:
    620             self.load()

PIL/Image.py in _copy(self)
    609 
    610     def _copy(self):
--> 611         self.load()
    612         self.im = self.im.copy()
    613         self.pyaccess = None

PIL/TiffImagePlugin.py in load(self)
   1055     def load(self):
   1056         if self.tile and self.use_load_libtiff:
-> 1057             return self._load_libtiff()
   1058         return super().load()
   1059 

PIL/TiffImagePlugin.py in _load_libtiff(self)
   1159 
   1160         if err < 0:
-> 1161             raise OSError(err)
   1162 
   1163         return Image.Image.load(self)

OSError: -9

有没有办法启用更有用的调试信息,以便我知道故障发生在哪里?需要明确的是,调用image.save时发生了错误。Image.save使用libtiff执行以下操作来操作文件:

decoder = Image._getdecoder(
            self.mode, "libtiff", tuple(args), self.decoderconfig
        )
...
...
decoder.decode(...)

Tags: 文件inpyimageselfreturnifpil