In a shell script, I would like to check whether two PNG images are different in the sense that either the images have different sizes or at least one pixel of one image has a different RGBA than the corresponding pixel of the other image.
Hashing the two image files will not work because the images could be compressed differently or have a different comment or perhaps two pixels are fully transparent but the RGB components differ, etc.
I know how to check whether the file sizes are different using ImageMagick's convert
utility. As far as comparing the pixel values, I thought of using ImageMagick's compare
utility, but the exit code is always 0 if the command was successfully processed: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22451
What command line test can be used to compare the pixels of two PNG images for equality? Or perhaps there is a way to use compare
after all?
Find an image format which allows uncompressed RGBA, convert both files, and compare the output. Maybe something like this:
$ convert a.png a.rgba
$ convert b.png b.rgba
$ cmp {a,b}.rgba
a.rgba b.rgba differ: byte 1, line 1