Inspect Image Files Safely with ImageMagick identify
identify-im6.q16 reads an image and reports its dimensions, format, colour depth and metadata without touching the file itself. The examples use ImageMagick 6.9.12-98 Q16, installed here as package imagemagick-6.q16 version 8:6.9.12.98+dfsg1-5.2ubuntu0.1~esm14. The unqualified identify and identify-im6 names are aliases in this guide's command group.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes. You need a shell and at least one readable image file. No example needs sudo: identify reads the input and reports what it finds, and does not rewrite the source file.
1. Confirm the binary and version
Check which executable your shell will actually run, then ask it for its version:
$ command -v identify-im6.q16
/usr/bin/identify-im6.q16
$ identify-im6.q16 -version
Version: ImageMagick 6.9.12-98 Q16 x86_64 18038
...
The feature and delegate lines vary between installations; the version line is the checkpoint that matters. If the command is missing, install ImageMagick through your normal package-management process rather than copying a binary in from an unrelated host.
Checkpoint
Run identify-im6.q16 -version and note whether the major version is 6. This guide follows the installed ImageMagick 6 command and its manpage; another major version can accept different options or report different details.
2. Read the normal image summary
Swap in a real path. The command works out the format from the file's magic number, not just its suffix:
$ identify-im6.q16 /path/to/photo.jpg
/path/to/photo.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 2.1MiB 0.000u 0:00.000
The exact byte count and timing depend on the file and the machine. The summary normally gives the path, format, dimensions, page geometry, depth, colour space, approximate size and processing time. For a multi-image file, such as an animated image or a multi-page document, expect one line per image or frame.
Do not treat the suffix as proof of the format. A file called photo.jpg can be malformed, renamed, or a different format entirely. A successful identification only shows that ImageMagick could read the image; it is not a visual quality check.
3. Check dimensions and colour information explicitly
Reach for -format when another program or a review checklist needs stable fields. Quote the format string so the shell does not mangle it:
$ identify-im6.q16 -format '%f: %wx%h %m %z-bit %[channels]\n' /path/to/photo.jpg
photo.jpg: 4032x3024 JPEG 8-bit sRGB
%f is the file name, %w and %h are width and height, %m is the format, %z is the depth, and %[channels] reports the channel layout. The output still reads fine for a human, but it is far easier to parse than the default line. Keep the newline escape inside the single quotes when processing more than one file.
Dimensions are pixels unless the image metadata or a later operation says otherwise. A print resolution such as 300 DPI is not the same thing as a 300-pixel image. If physical resolution matters, pull density into a separate report rather than inferring it from width and height.
4. Count colours when that is the actual question
The ordinary summary does not calculate a unique-colour count by default; you have to ask for it:
$ identify-im6.q16 -define unique=true /path/to/photo.jpg
/path/to/photo.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 1.2e+06c 2.1MiB 0.000u 0:00.000
The exact count and layout vary with the image. A file that looks like a flat colour can still hold far more values than expected, thanks to compression, transparency or hidden detail. Counting colours costs more work than reading dimensions, so leave it out of a large-file scan unless it actually answers a real question.
This installed build also lists a dedicated -unique option that displays the number of unique colours directly. Use whichever of the two matches the script and ImageMagick version you have standardised on, and check the spelling locally with identify-im6.q16 -help before putting an uncommon option into a portable script.
5. Make a fast pre-flight check
When you only need the basic attributes, use -ping. It asks ImageMagick to work out image attributes efficiently, without a full decode:
$ identify-im6.q16 -ping /path/to/photo.jpg
/path/to/photo.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 2.1MiB 0.000u 0:00.000
Use this ahead of a batch operation when a full pixel read is unnecessary. It is still only an input check, not a guarantee that every later decode, colour conversion or export will succeed. Keep a full identify or application-level verification step when the next operation depends on complete pixel access.
For detailed attributes, use -verbose on one file at a time:
$ identify-im6.q16 -verbose /path/to/photo.jpg
Image:
Filename: photo.jpg
Format: JPEG (...)
Verbose output is deliberately not a fixed schema. It is great for investigating profiles, geometry and image properties, but a poor contract for a long-lived parser. Prefer a chosen -format string for anything automated.
6. Handle errors without hiding them
Missing or unreadable input produces a diagnostic and a non-zero status:
$ identify-im6.q16 /path/to/missing-image.png
identify-im6.q16: unable to open image `/path/to/missing-image.png': No such file or directory ...
$ printf 'status: %s\n' "$?"
status: 1
The file name and trailing diagnostic wording can differ. Check the path and permissions without changing anything:
$ test -r /path/to/photo.jpg && echo readable
readable
$ ls -l /path/to/photo.jpg
Do not pipe errors away just to keep a batch report looking tidy. Capture the exit status and report which input failed. A successful status means the command completed its read and report; it does not certify that the image is suitable for publication, safe to trust, or free of unwanted metadata.
7. Keep inspection read-only and safe
The manpage describes identify as strictly read only. Options such as -crop, -strip, -auto-orient and -negate can look like editing operations, but for identify they only describe an in-memory result and never save anything back to the input file. Even so, do not present such options as a stand-in for a real conversion command: a reader could copy them into a different ImageMagick tool, where the operation does write output.
Do not use sudo to inspect an image unless the file is deliberately restricted and your access policy allows it. Elevated access can expose private images and makes it easier to overlook an ownership or permission problem. If a service account cannot read the file, fix the intended file access, or run the check as that account, rather than making a broad directory world-readable.
If an image came from an untrusted source, treat its metadata and decoder warnings as data, not instructions. Keep ImageMagick patched through the operating system, limit batch inputs, and avoid granting a conversion service more filesystem access than it needs.
Done means
- Binary and version confirmed. You checked the installed ImageMagick 6.9.12-98 Q16 binary and package version.
- Summary understood. You can read the normal summary and know its format is detected from file content, not the suffix.
- Focused report available. You can produce a dimensions, format, depth and channel report with
-format. - Colour counts on demand only. You request unique-colour counts only when they answer a real question.
- Failures stay visible. Your scripts check the exit status and keep missing or unreadable inputs visible rather than hidden.
- Source untouched. You have not modified the source image or used elevated privileges unnecessarily.