ImageMagick identify — read image information
Use ImageMagick identify to read dimensions, format, colour depth, EXIF and page count. Includes the format string tokens and scripting-friendly one-liners.
identify reads only the file header rather than decoding the whole image, so it is cheap enough to run across thousands of files. On ImageMagick 7 it is magick identify; on IM6 it is identify.
Quick summary
identify photo.jpg
photo.jpg JPEG 1600x900 1600x900+0+0 8-bit sRGB 62790B 0.000u 0:00.000
The second geometry is the page geometry — for a cropped image it reveals the virtual canvas that +repage would remove.
Just the fields you want
identify -format '%f %wx%h %m %b\n' *.jpg
This is the form you want in scripts — one clean line per file, no parsing required.
Useful format tokens
| Token | Meaning |
|---|---|
%f | Filename |
%w / %h | Width / height in pixels |
%m | Format (JPEG, PNG…) |
%b | File size |
%n | Number of frames or pages |
%Q | JPEG quality the file was saved at |
%[colorspace] | Colour space |
%z | Bit depth |
%A | Whether an alpha channel is present |
%[EXIF:*] | Every EXIF tag |
Read EXIF without another tool
identify -format '%[EXIF:*]' photo.jpg
identify -format '%[EXIF:DateTimeOriginal] %[EXIF:Model]\n' photo.jpg
Count pages in a PDF or frames in a GIF
identify -format '%n\n' document.pdf
identify -format '%n\n' animation.gif
Everything about a file
identify -verbose photo.jpg
Long. Pipe it through grep or head. It includes the colour histogram, which is genuinely useful for working out how many distinct colours a graphic actually uses before quantising it.
Recover the JPEG quality a file was saved at
identify -format '%Q\n' photo.jpg
ImageMagick estimates this from the quantisation tables. Re-encoding at a higher number than the original does not restore quality — it just makes a bigger file. Match or go slightly below.
Find images that break a rule
# everything wider than 3000px
identify -format '%w %f\n' *.jpg | awk '$1 > 3000 {print $2}'
# everything that is not sRGB
identify -format '%[colorspace] %f\n' *.jpg | grep -v '^sRGB'
Check a file is actually what its extension claims
identify -format '%m %f\n' *.png | grep -v '^PNG'
Handy before a batch job, and a cheap sanity check on user uploads — though it is not a security control on its own.