Compare two png and save the second if different

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bigbilou
Posts: 1
Joined: 2018-03-27T06:17:55-07:00
Authentication code: 1152

Compare two png and save the second if different

Post by bigbilou »

Hi all,

I have discovered ImageMagick today, and used it to delete metadata for a large number of png tiles, and save a lot of space.
I think this tool could help me for another issue I have to deal with.

I create the tiles every day for example. Instead of update mobile devices with all the new tiles, I would like to send just these ones which have really been modified. I cannot use the date of creation of course. For the moment i create a md5 and compare it, but maybe ImageMagick could do it better than me.

I have seen COMPARE but i do not want to create a third png.

Any ideas?

Thanks a lot.

Clément
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compare two png and save the second if different

Post by fmw42 »

You do not need to save the output. Use null: in its place

Code: Select all

compare -metric rmse image1 image2 null:
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare two png and save the second if different

Post by snibgo »

md5 compares the physical files, including metadata that may have file creation timestamps etc. IM's "compare" will examine just the images.

I use "compare" when updating my webpages, comparing new versions of images with a local mirror of the website. If the images are the same, I don't need to upload the new image. This works in a script that extracts the difference number: for "-metric RMSE", "0" means there is no difference.
snibgo's IM pages: im.snibgo.com
Post Reply