Page 1 of 1

PNG resize of same file giving different results

Posted: 2011-11-21T01:14:14-07:00
by Linor
I'm trying to resize a set PNG files from a web source, and am depending on the hashes of the resulting files to be the same if the original file has not changed, while this is the case if I convert to a JPG file, it is not so for PNG files. When I copied the files to a different system for a test, the file creation times were exactly the same, at which point the resulting files were equal. Is there a way to have the convertion not take this creation time in account when writing the resulting PNG file?

The source files:

Code: Select all

db73b11ba8202711748260e06379ee2f  source1.png
db73b11ba8202711748260e06379ee2f  source2.png
Commands executed:

Code: Select all

convert source1.png -resize 38x38 thumb1.png
convert source1.png -resize 38x38 thumb1-again.png
convert source2.png -resize 38x38 thumb2.png
convert source1.png -resize 38x38 thumb1.jpg
convert source2.png -resize 38x38 thumb2.jpg
The resulting files, JPGs are the same, resize of the same file is the same, resize of a different file with the same contents is different:

Code: Select all

0644cc37e88694af33edcc704590027c  thumb1.jpg
0644cc37e88694af33edcc704590027c  thumb2.jpg

ad170e808448e244744057a75e360339  thumb1.png
ad170e808448e244744057a75e360339  thumb1-again.png
e7b371313639691532b65e7de744d3f8  thumb2.png
I'm running ImageMagick 6.6.2-6 2011-03-16 Q16 on Ubuntu

Re: PNG resize of same file giving different results

Posted: 2011-11-21T01:37:26-07:00
by Linor
After some searching I found the following (source http://www.imagemagick.org/Usage/formats/#png_write)
Normally if you write the same image separately to two PNG files the two files will not compare to be the same. That is because IM will also store an image creation date within the file. JPEG images do not have this problem, but they are lossy.

....

The solution is to save PNG images without any 'time stamps'. You can remove the timestamps individually or remove all timestamps using a 'date:* setting name. Note however you will probably need to escape the '*'.
Using the * however does not seem to work, so I opted for date:modified and just setting the source file modification dates to a fixed value. Which seems to do the trick.

Re: PNG resize of same file giving different results

Posted: 2011-11-21T03:48:29-07:00
by Linor
I stand corrected, +set date:modified removed the modified property from the file, and kept the create date, so changing the modify date still did not work. I ended up using +set date:create +set date:modify, which removes both dates from the file (which in theory the * should do)

Re: PNG resize of same file giving different results

Posted: 2011-11-28T17:28:46-07:00
by anthony
The example I gave using +set date:\* is no longer producing an identical result!
Basically the option is no longer removing the date meta-data!

Something has changed, and I am reporting this as a BUG

ASIDE: The example is...

Code: Select all

  convert logo: logo.jpg
  convert logo.jpg +set date:\* logo1.png

  sleep 2; touch logo.jpg
  convert logo.jpg +set date:\* logo2.png

  diff -s logo1.png logo2.png
verbose checks of logo1.png and logo2.png show dates were included in the images meta-data!

Re: PNG resize of same file giving different results

Posted: 2011-12-05T18:20:30-07:00
by anthony
Of course as Glenn pointed out to me
You could use
-define png:exclude-chunks=date
This gets rid of the date-related chunks inside the PNG encoder.
However this is specific to PNG and not the same as the general solution (which should work!)