Page 1 of 1

create/modify-date written into file

Posted: 2008-10-09T11:48:55-07:00
by Artanicus
It seems somewhere around version 6.4, IM started to add the create-date and modify-date directly into the image file. Now, in my humble opinion this is an unneeded feature, all modern filesystems are more than happy to store this information themselves, and outside the file data. The current behaviour becomes a problem when file differences are detected automaticly by comparing files or rather, their checksums. The exact same image files except with different timestamps (checksum still matches!) become two differing image files because a different timestamp is written into them.

If this is a new feature that is needed for something smart, is there a way to disable this behaviour at runtime? If not, there should be one IMO.

Heres a script to test if your version is affected, should work out of the box(assuming you have coreutils and IM installed):

Code: Select all

#!/bin/bash

# test jpg image
convert logo: logo.jpg

# convert into png, this is the process that the real application needs
convert logo.jpg logo.png
sum1="$(sha1sum logo.png)" # checksum to demo the results

sleep 1s # wait for time to pass so the timestamp is different
touch logo.jpg # renew timestamp of original

# convert again, expecting identical results
convert logo.jpg logo.png
sum2="$(sha1sum logo.png)"

[ "$sum1" != "$sum2" ] && echo "Conversion results not identical, timestamp was written to file!"

rm logo.jpg logo.png
On success, no output is produced, on fail a warning.

My results with it so far:
6.3.5.10(older stable for Gentoo) - works as expected, checksums match
6.4.0.6(latest stable for Gentoo) - fails, checksums differ
6.4.3.5(latest unstable for Gentoo) - fails, checksums differ

Re: create/modify-date written into file

Posted: 2008-10-09T12:11:11-07:00
by magick
We will investigate, however a solution that will work for you is
  • compare -metric mae 1.png 2.png null:
If the MAE is 0, the images are identical. That is what the compare utility is for, to compare two images without regard to the metadata.

Re: create/modify-date written into file

Posted: 2008-10-09T12:20:18-07:00
by Artanicus
magick wrote:We will investigate, however a solution that will work for you is
  • compare -metric mae 1.png 2.png null:
If the MAE is 0, the images are identical. That is what the compare utility is for, to compare two images without regard to the metadata.
Thanks, this method will get me back to a functioning setup, but it is simply not a fast enough solution to be a long-term one. I've been using sha1 sums on the fly with php when generating web pages, but reading all the images into Imagick objects and then comparing them is much too slow for this in the long run. The design sucks on my part, but checksums are fast enough to make it work pretty good (:

Re: create/modify-date written into file

Posted: 2009-04-01T10:49:16-07:00
by Cliff
I produce a whole site where the graphics are created on the fly and output from a perl script. The script generates the image and then either outputs it or gives a "304 Not Modified" header. The site is Can't Backspace if you want to see what I mean.

The 304 is based on an Etag which is based on an md5 of the output, hence the problem.

Is there really no way to prevent this extension being put into the file? Or at least into the blob?

Cliff.

Re: create/modify-date written into file

Posted: 2009-04-01T11:40:31-07:00
by magick
From the command line, remove the properties like this:
  • convert logo.jpg +set modify-date +set create-date logo.png
From the API, use DeleteImageProperty(image,"modify-date") to delete the image property.

Re: create/modify-date written into file

Posted: 2009-04-01T11:54:48-07:00
by Cliff
magick wrote: From the API, use DeleteImageProperty(image,"modify-date") to delete the image property.
That's great, thanks. Just what I need.

It's probably just a documentation problem but I can't see a way to do it from Perl.

Cliff.

Re: create/modify-date written into file

Posted: 2009-04-01T12:19:11-07:00
by magick
In PerlMagick, use this to delete option:
  • $im->Set('modify-date'=>undef);

Re: create/modify-date written into file

Posted: 2009-04-01T12:41:32-07:00
by Cliff
magick wrote:In PerlMagick, use this to delete option:
  • $im->Set('modify-date'=>undef);
I'm afraid i get:

Code: Select all

6.4.0
Exception 410: unrecognized attribute `modify-date' at ./x.pl line 20.
The code is:

Code: Select all

#!/usr/bin/perl
#
use warnings;
use strict;
use feature ':5.10';
use Image::Magick;

say $Image::Magick::VERSION;
my $img = new Image::Magick(magick => 'png');
my $err;
$err = $img->Set('100x100');
die $err if $err;
$err = $img->Read('xc:white');
die $err if $err;
$err = $img->Set('modify-date' => undef);
die $err if $err;
my $blob = $img->ImageToBlog;
binmode STDOUT;
print $blob unless -t STDOUT;

Re: create/modify-date written into file

Posted: 2009-04-01T13:01:59-07:00
by magick
You most likely need to upgrade ImageMagick to a more modern version. The current version is ImageMagick 6.5.1-0.

Re: create/modify-date written into file

Posted: 2009-04-01T14:47:43-07:00
by Cliff
magick wrote:You most likely need to upgrade ImageMagick to a more modern version. The current version is ImageMagick 6.5.1-0.
Slightly different response now:

Code: Select all

[cliff@twin keene]$ ./x.pl 
6.5.1
Use of uninitialized value in subroutine entry at ./x.pl line 20.
Use of uninitialized value in subroutine entry at ./x.pl line 20.
But that seems to be because the default: statement on the switch (line 2115 in Magick.xs) has somehow lost the old code which used to say:

Code: Select all

    default:
    {
      ThrowPerlException(exception,OptionError,"UnrecognizedAttribute",
        attribute);
      break;
    }
But still no sign of a handler for modify-date. I've checked trunk too.

Cliff.

Re: create/modify-date written into file

Posted: 2009-04-01T16:09:11-07:00
by Cliff
Cliff wrote:But that seems to be because the default: statement on the switch (line 2115 in Magick.xs) has somehow lost the old code
OK, I have now understood what the point of those changes is; it's supposed to allow random properties to be set. I'm not sure Set() is the best way to set and unset properties as it removes a whole level of syntax checking on attribute Set()ing but, in the interests of getting my site working, I've produced a patch against trunk that seems to allow for $img->Set(property => undef); correctly.

It's too long to post here. I'll mail it to the Magick-bugs mailing list. I hope that's the right procedure.

Cliff.

Re: create/modify-date written into file

Posted: 2009-04-01T19:37:44-07:00
by magick
The magick-bugs mailing list does not accept patches. You should be able to send us a PM or post a URL to the patch here.