The fastest way to read an image's width and height from the terminal is ImageMagick's identify:
magick identify -format "%w %h" photo.jpgThat prints 1920 1080 (width then height) and nothing else, which is exactly what you want when you are piping it into a script or pasting it into a <PostImage> width/height. The rest of this page covers the variants: a print-style format string, the built-in macOS option that needs nothing installed, a rough one-liner with file, the video equivalent with ffprobe, and a loop for a whole folder.
Which tool to reach for:
| Tool | Install | Best for | Scriptable |
|---|---|---|---|
magick identify | ImageMagick (separate install) | Anything you script; widest format support | Yes, with -format "%w %h" |
sips | Built into macOS | A one-off check on a Mac with nothing installed | Yes, but labelled output needs parsing |
file | On nearly every Unix system | A rough glance when nothing else is around | No, the string is free-form |
ffprobe | ffmpeg (separate install) | Video resolution, not still images | Yes, with -of csv=p=0 |
ImageMagick: identify
If you only need a quick human-readable look, run identify with no format string at all:
magick identify photo.jpgThat gives you a line like photo.jpg JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 412KB. The first 1920x1080 is the dimensions; the rest is geometry, depth, colorspace, and file size. Handy for eyeballing, noisy for scripting.
For scripting, pin the output down with -format. The %w and %h specifiers are width and height in pixels:
# Just the numbers, space-separated
magick identify -format "%w %h" photo.jpg
# The classic WxH string
magick identify -format "%wx%h\n" photo.jpgOn ImageMagick 7 the command is magick identify. The bare identify (and convert) still work as legacy aliases, so if you are on an older box or a script you inherited, identify -format "%w %h" photo.jpg does the same thing. ImageMagick reads dimensions out of the header without decoding the whole image, so it is fast even on large files, and it handles far more than JPEG and PNG: it will read the canvas size of a PSD, a TIFF, a WebP, and so on. (PDF page sizes work too, but only when ImageMagick has its Ghostscript delegate installed, since it shells out to Ghostscript to read PDFs.)
A note worth keeping: identify is cross-platform (Linux, macOS via Homebrew, Windows), but it is a separate install. On macOS that is brew install imagemagick; on Debian or Ubuntu, sudo apt install imagemagick. If you would rather not install anything on a Mac, the next option is built in.
macOS: sips (nothing to install)
sips (Scriptable Image Processing System) ships with macOS, so on any Mac you can read dimensions with zero setup:
sips -g pixelWidth -g pixelHeight photo.pngIt prints the path followed by labelled lines:
/Users/you/photo.png
pixelWidth: 1920
pixelHeight: 1080-g queries a single property; pass it twice for both. sips -g all photo.png dumps everything it knows (DPI, colorspace, format, profile). The labelled output is friendlier to read than identify but slightly more work to parse in a script, so if you are scripting on a Mac and already have ImageMagick installed, identify -format is cleaner. For a one-off check on a stock Mac, sips wins because there is nothing to install.
A quick guess with file
file is on virtually every Unix system and will tell you the dimensions as part of its type description:
file photo.pngYou get something like photo.png: PNG image data, 1920 x 1080, 8-bit/color RGB, non-interlaced. This is a convenience, not a contract: the dimension string is part of free-form text whose exact wording varies by format and by file version, and some formats report no dimensions at all. Use it when ImageMagick is not installed and you just want a glance. For anything you parse, reach for identify or sips.
Video: ffprobe
An image tool will not read a video's resolution; for that, use ffprobe, which ships with ffmpeg:
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 clip.mp4That prints 1920,1080. Breaking it down: -v error silences ffprobe's normal banner so only the answer comes back; -select_streams v:0 targets the first video stream (a file can carry several streams, and you do not want the audio stream's blank dimensions); -show_entries stream=width,height asks for just those two fields; and -of csv=p=0 formats them as bare comma-separated values with no key prefix. Swap the output to -of default=noprint_wrappers=1 if you would rather see width=1920 / height=1080 labelled.
Batch over a folder
To print dimensions for every image in a directory, loop and let identify do the work per file:
for f in *.jpg *.png; do
echo "$f: $(magick identify -format "%wx%h" "$f")"
doneQuote "$f" so filenames with spaces survive. If a glob matches nothing (say there are no .png files), bash passes the literal pattern through and identify errors on it; shopt -s nullglob before the loop makes an empty glob expand to nothing instead. On macOS without ImageMagick, the same idea works with sips, which already accepts multiple files in one call:
sips -g pixelWidth -g pixelHeight *.pngFAQ
See also
- The ffmpeg command cheat sheet: convert, crop, trim, and inspect video from the CLI, including more ffprobe.
- Inspect an animated GIF from the command line: frame count, first frame, and animated-or-not with the same
identifytool. - Convert an image to grayscale with ImageMagick: grayscale, true black and white, and the difference between them.
Sources
Authoritative references this article was fact-checked against.
- ImageMagick identify (official documentation)imagemagick.org
- ImageMagick format and print image properties (%w, %h escapes)imagemagick.org
- Porting to ImageMagick version 7 (legacy command aliases)imagemagick.org
- sips command reference for macOSss64.com
- ffprobe documentation (official)ffmpeg.org





