Validate an image file using ImageMagick

If you ever want to check whether an image file is valid or has been corrupted, you can use ImageMagick to do so. ImageMagick is available for Mac OS X via hombrew, making installing and using it quick and simple.

Installing ImageMagick with homebrew

ImageMagick can be installed with one command. However, ImageMagick depends on Ghostscript fonts, so you need to install them alongside ImageMagick:

$ brew install ghostscript imagemagick

Verifying images with ImageMagick

Once installed, you can use the magick command:

$ magick -help
Usage: magick tool [ {option} | {image} ... ] {output_image}
Usage: magick [ {option} | {image} ... ] {output_image}
       magick [ {option} | {image} ... ] -script {filename} [ {script_args} ...]
       magick -help | -version | -usage | -list {option}

To identify whether an image is corrupt, use the identify option with the +ping option to ensure accurate image properties.

Let’s look at a valid image:

 $ magick identify +ping  image.png
image.png PNG 2552x1654 2552x1654+0+0 8-bit TrueColorAlpha sRGB 278747B 0.060u 0:00.039

Now, let’s look at a corrupted image:

$ magick identify +ping  _04F36204-1DD8-B71B-0BC4-784BE45D3203.jpeg
_04F36204-1DD8-B71B-0BC4-784BE45D3203.jpeg JPEG 4216x2806 4216x2806+0+0 8-bit sRGB 1.78372MiB 0.060u 0:00.061
identify: Premature end of JPEG file `_04F36204-1DD8-B71B-0BC4-784BE45D3203.jpeg' @ warning/jpeg.c/JPEGWarningHandler/411.
identify: Corrupt JPEG data: premature end of data segment `_04F36204-1DD8-B71B-0BC4-784BE45D3203.jpeg' @ warning/jpeg.c/JPEGWarningHandler/411.

Using ImageMagick, you can, among many other amazing things, validate an image and check whether it is corrupt.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top