Python:读取 png 图像的默认/常用方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2200742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: default/common way to read png images
提问by Albert
I haven't found a standard way in Python to read images. Is there really none (because there are so many functions for so many custom stuff that I really wonder that there are no functions to read images)? Or what is it? (It should be available in the MacOSX standard installation and in most recent versions on Linux distributions.)
我还没有在 Python 中找到读取图像的标准方法。真的没有吗(因为有这么多自定义东西的功能,我真的很想知道有没有读取图像的功能)?或者是什么?(它应该在 MacOSX 标准安装和 Linux 发行版的最新版本中可用。)
If there is none, what is the most common lib?
如果没有,最常见的lib是什么?
Many search results hint me to Python Imaging Library. If this is some well known Python-lib for reading images, why isn't it included in Python?
许多搜索结果提示我使用 Python Imaging Library。如果这是一些众所周知的用于读取图像的 Python 库,为什么它不包含在 Python 中?
回答by AndiDog
No, there are no modules in the standard library for reading/writing/processing images directly. But the most common library might be PIL (Python Imaging Library). Many projects are not included in the standard library because they are 1) totally optional and 2) cannot be maintained by the few Python core developers.
不,标准库中没有直接读取/写入/处理图像的模块。但最常见的库可能是PIL (Python Imaging Library)。许多项目没有包含在标准库中,因为它们 1) 完全可选和 2) 不能由少数 Python 核心开发人员维护。
回答by Tom Swirly
Coming late to the party, I would strongly suggest one of the Python interfaces to the ImageMagicklibrary (Wand worked well in my testing, I'll know more soon...)
迟到了,我强烈建议使用 ImageMagick库的Python 接口之一(Wand 在我的测试中运行良好,我很快就会知道更多......)
ImageMagick is a more powerful library and also pretty well a de-facto standard across many languages. Appealing to a wider base, they also have a wider developer base as a result.
ImageMagick 是一个更强大的库,也是跨多种语言的事实上的标准。吸引更广泛的基础,因此他们也拥有更广泛的开发人员基础。
回答by user266458
THe suggested PIL does not support interlaced PNGs. It can be quite anoying when dealing with lots of PNGs from different origins. It is possible to open them, but can only read headerinformation from them, all other operations fail.
建议的 PIL 不支持隔行扫描 PNG。处理来自不同来源的大量 PNG 时可能会非常烦人。可以打开它们,但只能从中读取头信息,所有其他操作都失败。