Fast way to get image dimensions (not filesize)

前端 未结 8 1667
独厮守ぢ
独厮守ぢ 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:24
    • The file command prints the dimensions for several image formats (e.g. PNG, GIF, JPEG; recent versions also PPM, WEBP), and does only read the header.

    • The identify command (from ImageMagick) prints lots of image information for a wide variety of images. It seems to restrain itself to reading the header portion (see comments). It also has a unified output which file sadly lacks.

    • exiv2 gives you dimensions for many formats, including JPEG, TIFF, PNG, GIF, WEBP, even if no EXIF header present. It is unclear if it reads the whole data for that though. See the manpage of exiv2 for all supported image formats.

    • head -n1 will give you the dimensions for PPM, PGM formats.

    For formats popular on the web, both exiv2 and identify will do the job. Depending on the use-case you may need to write your own script that combines/parses outputs of several tools.

    0 讨论(0)
  • 2021-01-29 23:25

    I not sure you have php installed, but this PHP function is pretty handy

     php -r "print_r(getimagesize('http://www.google.com/images/logos/ps_logo2.png'));"
    
    0 讨论(0)
提交回复
热议问题