PNG writer stores creation date unconditionally?

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
wkoszek
Posts: 9
Joined: 2015-11-16T19:30:51-07:00
Authentication code: 1151

PNG writer stores creation date unconditionally?

Post by wkoszek »

Hello,

I attempted to create myself some test data as a part of my testdata GitHub repo:

https://github.com/wkoszek/testdata/blob/master/gen.rb

I see Image Magick's PNG writer behaving in an unexpected way, which doesn't match JPG writer. Issue is related to conditions in which ImageMagick will embed a timestamp in the image.

Replicated the case through this snippet:

https://gist.github.com/wkoszek/376b93a29ee4cd9c91d6

Explanation:
- made date1.png and date2.png at different times. I see MD5 differ, meaning creation date is embedded in the image.
- made date1.jpg and date2.jpg at different times. I see MD5 be the same, meaning creation date isn't embedded in the image.
- made nodate1.png and nodate2.png at different times, but with an explicit request to not put the date in the PNG. I see MD5 is still different.

I use `png:exclude-chunk=time` since that's what I found on this forum. So far I'm not having luck with it.

My target is to make my script generate the file that is identical each time it's run, regardless of time. Shouldn't such behavior be the default?

Thanks,

Wojciech Koszek
wojciech@koszek.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG writer stores creation date unconditionally?

Post by fmw42 »

I am not a PNG expert, but see +set date at http://www.imagemagick.org/Usage/formats/#png_write
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG writer stores creation date unconditionally?

Post by glennrp »

wkoszek wrote: I use `png:exclude-chunk=time` since that's what I found on this forum. So far I'm not having luck with it.
Try `-define png:exclude-chunk=date'
wkoszek
Posts: 9
Joined: 2015-11-16T19:30:51-07:00
Authentication code: 1151

Re: PNG writer stores creation date unconditionally?

Post by wkoszek »

It's either a bug, or I'm doing something very wrong. I tried -png:exclude-chunk=date, and +set and nothing seems to work. My updated script and the output logs:

https://gist.github.com/wkoszek/fa13a4dc0d1237554f62
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG writer stores creation date unconditionally?

Post by fmw42 »

-png:exclude-chunk=date
try -define png:exclude-chunk=date, if glennrp is correct, not -png:...
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG writer stores creation date unconditionally?

Post by glennrp »

fmw42 wrote:
-png:exclude-chunk=date
try -define png:exclude-chunk=date, if glennrp is correct, not -png:...
The log says wkoszek did that. But it was followed with

Code: Select all

-define png:exclude-chunks=time
which replaced the list of chunks to be excluded (date) with a new list (time). To exclude
multiple chunks, use

Code: Select all

-define png:exclude-chunks=date,time
instead of multiple "-define png:exclude-chunks=something" options. I'll look into improving the documentation (or the behavior) of that feature.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG writer stores creation date unconditionally?

Post by fmw42 »

Glenn,

Thanks for clarifying that.
wkoszek
Posts: 9
Joined: 2015-11-16T19:30:51-07:00
Authentication code: 1151

Re: PNG writer stores creation date unconditionally?

Post by wkoszek »

Hi guys

https://gist.github.com/wkoszek/fa13a4dc0d1237554f62

I tried all the versions of flags/switches from this block:

Code: Select all

#f="+set date:create +set date:modify"
#f="-define png:exclude-chunks=time"
#f="-define png:exclude-chunks=tIME"
#f="-define png:exclude-chunks=date,time"
f="-define png:exclude-chunks=date -define png:exclude-chunks=time" 
e.g.: I tried line 4 by itself too (with line 5 commented out). It doesn't work.

Wojciech
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG writer stores creation date unconditionally?

Post by glennrp »

Put the "$f" last (just before the output filename).
wkoszek
Posts: 9
Joined: 2015-11-16T19:30:51-07:00
Authentication code: 1151

Re: PNG writer stores creation date unconditionally?

Post by wkoszek »

Result is the same. Seems like it doesn't work either that way. What I've run:

http://pastebin.com/eAtWmQ0S
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG writer stores creation date unconditionally?

Post by glennrp »

I'm testing a fix. The bug is in coders/png.c; we test for "Date:" instead of "date:".
wkoszek
Posts: 9
Joined: 2015-11-16T19:30:51-07:00
Authentication code: 1151

Re: PNG writer stores creation date unconditionally?

Post by wkoszek »

Is there a workaround for this? Something I could use with ImageMagick shipped with "brew" or "apt-get" ?

Thanks for confirming,
W.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG writer stores creation date unconditionally?

Post by glennrp »

I'd use the "signature" instead of MD5 to identify identical images.

identify -verbose file1.png | grep ignature
identify -verbose file2.png | grep ignature

I omit the first letter of "signature" because I can never remember whether
it is capitalized or not.
wkoszek
Posts: 9
Joined: 2015-11-16T19:30:51-07:00
Authentication code: 1151

Re: PNG writer stores creation date unconditionally?

Post by wkoszek »

While I don't know what identify does, I know md5/sha1 utilities do pretty much what git will when I commit a file.

I was asking about a workaround for the PNG generation, since I think brew will catch up from the upstream with slight delay.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG writer stores creation date unconditionally?

Post by glennrp »

wkoszek wrote:While I don't know what identify does, I know md5/sha1 utilities do pretty much what git will when I commit a file.
The difference is that the "signature" reported by "identify" is calculated over the pixel date, not over the file. Therefore, the presence of "Creation date" metadata doesn't change the signature. In fact, even representing the image in a different format doesn't change the signature:
  • glenn.rp> convert logo: logo.gif
    glenn.rp> convert logo: logo.png
    glenn.rp> identify -verbose logo: logo.gif logo.png | grep ignature
    signature: 5c701306a9a985a0c93c8d11a1e761d7f8637577697fc60d7189b221388f8edf
    signature: 5c701306a9a985a0c93c8d11a1e761d7f8637577697fc60d7189b221388f8edf
    signature: 5c701306a9a985a0c93c8d11a1e761d7f8637577697fc60d7189b221388f8edf
    glenn.rp>
Post Reply