【问题标题】:Use Python to find the resolution of image with any image file extension without using any non-default library在不使用任何非默认库的情况下,使用 Python 查找具有任何图像文件扩展名的图像的分辨率
【发布时间】:2022-01-06 02:09:36
【问题描述】:

如何在不使用任何不属于 Python 标准库的模块(可能 PIL 除外)的情况下找到具有 any 扩展名的图像的分辨率?

【问题讨论】:

标签: python python-imaging-library


【解决方案1】:

您可以使用Pillow 包获取图像的分辨率:

from PIL import Image

with Image.open("filename") as image:
    width, height = image.size

您可以在documentation中找到更多信息

正如 pippo1980 所指出的,这是针对图像的尺寸而不是针对图像的分辨率。为了完整起见,以下是获取图像分辨率的方法:

from PIL import Image

with Image.open("filename") as image:
    xres, yres = image.info['dpi']

【讨论】:

  • 以像素为单位的图像尺寸不是分辨率
  • @pippo1980 你说得对,我倾向于互换使用这些术语,但以防万一其他人遇到问题,我已经更新了答案
  • 其实我不知道 xres 和 yres !!!谢谢也看到这里:stackoverflow.com/questions/54517814/using-pillow-to-find-dpi 从来没有想过非方形像素
猜你喜欢
  • 1970-01-01
  • 2023-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-13
  • 1970-01-01
  • 1970-01-01
  • 2015-11-12
相关资源
最近更新 更多