How to compare 2 images from command line

FreeBSD freebsd at
Tue Sep 2 15:58:22 UTC 2008

Bill Moran a écrit :
> In response to FreeBSD <freebsd at>:
>> Andrew Gould a écrit :
>>> On Tue, Sep 2, 2008 at 10:23 AM, FreeBSD <freebsd at 
>>> <mailto:freebsd at>> wrote:
>>>     Tom Marchand a écrit :
>>>         Hash the images and compare the hashes.
>>>          -------------- Original message ----------------------
>>>         From: FreeBSD <freebsd at
>>>         <mailto:freebsd at>>
>>>             Hi everyone,
>>>             I'm trying to determine if 2 jpeg images are identical. The
>>>             images are screenshots taken with scrot at different times.
>>>             The point is to know if the display is working correctly. I
>>>             tried to use 'diff' but without success, probably because of
>>>             the metadata included in the image. I also tried the
>>>             'compare' command from imagemagick, but it produce an image
>>>             containing the difference between the 2 images instead of
>>>             telling me if both images are identical.
>>>             So, my question is what are you using to determine if 2
>>>             images are identical?
>>>             I'm using FreeBSD 7.0 and I need to be able to script this
>>>             comparaison for an integration in Nagios.
>>>             Thank you,
>>>             Martin
>>>     I just tried it and it doesn't work. The hashes are different. I can't
>>>     say that I'm surprised since 'diff' is "seeing" a difference between the
>>>     two identical images.
>>>     Thanks for the suggestion
>>> Yes, there's a huge difference between testing differences in images and 
>>> testing differences in files.  What do you mean by "...know if the 
>>> display is working correctly."?
>>> Andrew
>> I want to determine if Mplayer is working correctly. The best way to be 
>> sure is to check if the display on the screen is changing. That's the 
>> purpose of the screenshots. The screenshots are taken by Nagios every 5 
>> minutes and the new screenshot is compared with the preceding one. But, 
>> by now, it doesn't work because every tool we try is seeing a diffence 
>> between 2 identical images.
> Can you put the screenshots into some other format?  As you mentioned,
> the jpeg format includes metadata, which might include the creation
> time and would cause every image to be unique from a filesystem view.
> For example, I don't believe bitmaps include metadata, which would cause
> them to be identical if the display were identical.

Thank you! It did the trick. I just converted the image from png (sorry 
it wasn't jpeg...) to bmp and it works with cmp. Even diff now recognize 
both images as identical.

Thanks everyone for your support.


More information about the freebsd-questions mailing list