From 10c6da3a6cb5138b7ab1d05be9759772648e7ffc Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Thu, 3 Aug 2017 22:10:55 -0400 Subject: [PATCH] Put UTC time in the PNG tIME chunk instead of local time (reference https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=32447). --- ChangeLog | 4 ++++ coders/png.c | 54 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3566e7ea1..8e333b2b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-08-03 7.0.6-6 Glenn Randers-Pehrson + * Put UTC time in the PNG tIME chunk instead of local time (reference + https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=32447). + 2017-08-02 7.0.6-5 Cristy * Release ImageMagick version 7.0.6-5, GIT revision 20715:26b28d50a:20170802. diff --git a/coders/png.c b/coders/png.c index f9bea7f4c..ece03b191 100644 --- a/coders/png.c +++ b/coders/png.c @@ -8148,37 +8148,51 @@ static void write_tIME_chunk(Image *image,png_struct *ping,png_info *info, minute, month, second, - year; + year, + addhours=0, + addminutes=0; png_time ptime; - time_t - ttime; - - if (date != (const char *) NULL) + if (date == (const char *) NULL) { - if (sscanf(date,"%d-%d-%dT%d:%d:%dZ",&year,&month,&day,&hour,&minute, - &second) != 6) - { + const char + *timestamp; + + timestamp=GetImageProperty(image,"date:modify",exception); + if (sscanf(timestamp,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour, + &minute, &second, &addhours, &addminutes) != 8) + { (void) ThrowMagickException(exception,GetMagickModule(),CoderError, "Invalid date format specified for png:tIME","`%s'", image->filename); return; - } - ptime.year=(png_uint_16) year; - ptime.month=(png_byte) month; - ptime.day=(png_byte) day; - ptime.hour=(png_byte) hour; - ptime.minute=(png_byte) minute; - ptime.second=(png_byte) second; + } } else - { - time(&ttime); - png_convert_from_time_t(&ptime,ttime); - } - png_set_tIME(ping,info,&ptime); + { + if (sscanf(date,"%d-%d-%dT%d:%d:%d%d:%d",&year,&month,&day,&hour, + &minute, &second, &addhours, &addminutes) != 8) + { + (void) ThrowMagickException(exception,GetMagickModule(),CoderError, + "Invalid date format specified for png:tIME","`%s'", + image->filename); + return; + } + } + ptime.year=(png_uint_16) year; + ptime.month=(png_byte) month; + ptime.day=(png_byte) day; + ptime.hour=(png_byte) hour+addhours; + ptime.minute=(png_byte) minute+addminutes; + if (ptime.minute > 60) + { + ptime.hour++; + ptime.minute=+60; + } + ptime.second=(png_byte) second; + png_set_tIME(ping,info,&ptime); } #endif -- 2.40.0