python - 用于图像验证的 PIL 或 imghdr

标签 python django python-imaging-library imghdr

我正在开发一个可以处理图像上传的网站,因此我需要验证图像是否有效, 我有两个选择,我要么使用 PIL(Pillow),要么使用 imghdr 模块。

我的问题是,我应该使用哪一个? 由于 PIL 没有被维护,imghdr 模块会完成这项工作吗? 其中哪一个是安全和/或高效的?

谢谢。

最佳答案

请注意,PIL 和 Pillow 不是同一个包。 Pillow 是 PIL 的一个分支,被认为是 PIL 的继承者。

要处理网站中的图像(我假设由于您的标签,这是一个 django 项目),建议使用 Pillow 。例如,如果您想使用 ImageField ,它需要 Pillow 库。

关于python - 用于图像验证的 PIL 或 imghdr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25504420/

相关文章:

python - 导入错误 : No module named PIL

python - Pillow :libopenjp2.so.7:无法打开共享对象文件:没有这样的文件或目录

python - pandas - 将没有分隔符的文本列拆分为多列

python - 在 Linux 或更好的跨平台上全局检测用户空闲(无用户输入)时间

python - 求解 x^2 + y^2 + z^2 = N 得到 x, y, z 的所有唯一组合

javascript - 如何在 Python 中解压 Javascript

django - celery : Execute task after a specific time gap

python - 我如何计算 Django 中的多个关系

python - 在ubuntu中升级python

Python:如何将 Sympy 图像导出为 png?