How to obtain image size using standard Python class (without using external library)?

后端 未结 10 1550
有刺的猬
有刺的猬 2020-11-29 18:02

I am using Python 2.5. And using the standard classes from Python, I want to determine the image size of a file.

I\'ve heard PIL (Python Image Library), but it requi

10条回答
  •  囚心锁ツ
    2020-11-29 18:42

    It depends on the output of file which I am not sure is standardized on all systems. Some JPEGs don't report the image size

    import subprocess, re
    image_size = list(map(int, re.findall('(\d+)x(\d+)', subprocess.getoutput("file" + filename))[-1]))
    

提交回复
热议问题