create/modify-date written into file

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
Artanicus

create/modify-date written into file

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: create/modify-date written into file

Post 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.
Artanicus

Re: create/modify-date written into file

Post 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 (:
Cliff

Re: create/modify-date written into file

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: create/modify-date written into file

Post 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.
Cliff

Re: create/modify-date written into file

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: create/modify-date written into file

Post by magick »

In PerlMagick, use this to delete option:
  • $im->Set('modify-date'=>undef);
Cliff

Re: create/modify-date written into file

Post 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;
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: create/modify-date written into file

Post by magick »

You most likely need to upgrade ImageMagick to a more modern version. The current version is ImageMagick 6.5.1-0.
Cliff

Re: create/modify-date written into file

Post 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.
Cliff

Re: create/modify-date written into file

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: create/modify-date written into file

Post 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.
Post Reply