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

后端 未结 10 1562
有刺的猬
有刺的猬 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 19:07

    If you happen to have ImageMagick installed, then you can use 'identify'. For example, you can call it like this:

    path = "//folder/image.jpg"
    dim = subprocess.Popen(["identify","-format","\"%w,%h\"",path], stdout=subprocess.PIPE).communicate()[0]
    (width, height) = [ int(x) for x in re.sub('[\t\r\n"]', '', dim).split(',') ]
    

提交回复
热议问题