在不访问受保护成员的情况下使用 pillow 访问 EXIF 数据

Access EXIF data using pillow without accessing a protected member

我找到的使用 pillow 访问图像的 EXIF 元数据的示例使用了 PIL.Image 的受保护成员 _getexif()。 Pylint 将通过以下警告对此进行投诉:

[W0212(protected-access), functionname] Access to a protected member _getexif of a client class

有没有办法在不通过受保护成员的情况下获取图像的 EXIF 数据?

_getexif() 是下划线,因为他们不想承诺它总是像现在这样工作 - 代码说 "This method is highly experimental, and is likely to be replaced with something better in a future version." 尽管据我所知,据说在PIL 年龄.

所以你的选择是:

  • 抑制 lint 警告
  • 使用 i.info.get('exif') 获取原始(未解析的)exif 数据并自行解析,可能使用从 Pillow 中提取的代码
  • 使用支持的 exif 库,例如 ExifRead

edit:真的 "don't want to commit to it always working the way it does now" 有点低估了 - _getexif() 是供图书馆自己(非常有限)的内部使用,他们认识到解析在野外发现的 真实 exif,并为所有人(甚至是奇怪的)提供可靠的结果是一项比他们愿意注册的更重要的任务。