Fast way to get image dimensions (not filesize)

前端 未结 8 1701
独厮守ぢ
独厮守ぢ 2021-01-29 23:03

I\'m looking for a fast way to get the height and width of an image in pixels. It should handle at least JPG, PNG and TIFF, but the more the better. I emphasize

8条回答
  •  走了就别回头了
    2021-01-29 23:18

    Imagemagick -ping option

    It seems to have been introduced for that purpose.

    However as of ImageMagick 6.7.7 I don't observe slowdown even for every large files, e.g.:

    head -c 100000000 /dev/urandom > f.gray
    # I don't recommend that you run this command as it eats a lot of memory.
    convert -depth 8 -size 20000x10000 f.gray f.png
    identify f.png
    

    Can you produce an example input image for which it is still slow?

    See also: Can ImageMagick return the image size?

提交回复
热议问题