Nono.MA

Get image width and height with ImageMagick

MAY 28, 2022

You can ask ImageMagick for details of image files with the identify. Say, their dimensions (width and height), their resolution (pixels-per-inch), or many other details.

You can run the identify by itself to get a series of default details.

The Identify command

identify image.jpg
# image.jpg JPEG 1600x1659 1600x1659+0+0 8-bit sRGB 475062B 0.010u 0:00.002

The -verbose flag

Or even to obtain greater details with the -verbose flag. (Note that this command returns more than 300 lines of information per image, so I'm omitting most of what was returned.)

identify -verbose image.jpg
# Image:
#  Filename: image.jpg
#  Format: JPEG (Joint Photographic Experts Group JFIF format)
#  Mime type: image/jpeg
#  Class: DirectClass
#  Geometry: 1600x1659+0+0
#  Resolution: 200x200
#  ...

Width and Height of a single image

identify -format "%wx%h" image.jpg
# 1600x1659

Width and Height of multiple images in a directory

identify -format "%wx%h\n" *.jpg
# 1983x1969
# 1912x1803
# 2173x2126
# 1807x1669
# ...

Dimensions and names

identify -format "%wx%h - %f\n" *.jpg
# 1983x1969 - image-01.jpg
# 1912x1803 - image-02.jpg
# 2173x2126 - image-03.jpg
# 1807x1669 - image-04.jpg
# ...

For reference, here are ImageMagick's identify docs.

BlogCodeImagemagick