"Canonicalize" PNG files

0

I am looking for a way to process a set of PNG files in such a way that if they contain the same image data, the files will be byte-by-byte identical too.

Is there a quick and easy, automatable way to achieve this in Linux?

Reasons why two files that encode the same image may not be identical:

  • metadata such as creator and time stamp
  • different compression (or compression level)

Basically I am looking for a way to strip the metadata and recompress each file (even if recompression results in a larger file, which tools like optipng do not do).

Szabolcs

Posted 2019-12-07T13:17:57.737

Reputation: 2 248

Use something like imagemagic convert or png2bmp and then check for byte for byte similarity?

– Mokubai – 2019-12-07T14:01:06.010

Is the idea that you will always use the same compression in the future, whatever that is, so it would not be a factor contributing to a difference? Even if you strip the metadata, if the file is changed in any way, it will get new metadata. So it isn't clear how a standardized compression helps in comparing the file to something else. If the purpose is just to verify that the file is unchanged, it can be unchanged vs. whatever its current compression is. Also, directory metadata isn't part of the file. Are you referring to selective data in the file header? – fixer1234 – 2019-12-07T22:00:55.563

Same as Mokubai. The PNG format has a tIME chunk (down to the second), so PNG are different if not created at the same time. You would have to obliterate it or convert the PNGs withing the same second (hard to do, even with parallel). It could be easier to convert to a "dumb" format such as BMP. – xenoid – 2019-12-08T11:18:59.090

No answers