Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell test for "images are different"?

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?

like image 984
Daniel Trebbien Avatar asked Apr 25 '26 00:04

Daniel Trebbien


1 Answers

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
like image 95
PhilR Avatar answered Apr 26 '26 14:04

PhilR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!