[gimp/gimp-2-10] libgimp: fix #1632 GIMP should not write to IPTC tag DateCreated



commit 34502e38294e9aadb17806602a64d752b0215cb8
Author: Jacob Boerema <jgboerema gmail com>
Date:   Mon Jun 6 21:34:34 2022 -0400

    libgimp: fix #1632 GIMP should not write to IPTC tag DateCreated
    
    GIMP was saving the last changed/saved date to IPTC tag DateCreated,
    which should only be used for the original creating date of the image
    and thus should not be changed by GIMP.
    
    After discussion in the cited issue, there is no tag in IPTC that we can
    use, so we remove saving modified date from the IPTC metadata.
    
    Instead we add two XMP tags, one for modified date and the other for the
    date that metadata was changed. Since we do both when exporting, both are
    saved with the same date/time in ISO 8601 format.
    
    This also fixes another issue where we were not storing the timezone offset
    for Xmp.tiff.DateTime. Since this has the same format as the other
    XMP tags, we fix this together with this issue.

 libgimp/gimpimagemetadata.c | 42 +++++++++++++-----------------------------
 1 file changed, 13 insertions(+), 29 deletions(-)
---
diff --git a/libgimp/gimpimagemetadata.c b/libgimp/gimpimagemetadata.c
index a8af509f8f..4fccaba78c 100644
--- a/libgimp/gimpimagemetadata.c
+++ b/libgimp/gimpimagemetadata.c
@@ -288,6 +288,7 @@ gimp_image_metadata_save_prepare (gint32                 image_ID,
       gdouble             xres;
       gdouble             yres;
       gchar               buffer[32];
+      gchar              *datetime_buf = NULL;
       GExiv2Metadata     *g2metadata = GEXIV2_METADATA (metadata);
 
       image_width  = gimp_image_width  (image_ID);
@@ -348,6 +349,16 @@ gimp_image_metadata_save_prepare (gint32                 image_ID,
                                       "Xmp.dc.Format",
                                       mime_type);
 
+      /* XMP uses datetime in ISO 8601 format */
+      datetime_buf = g_date_time_format (datetime, "%Y:%m:%dT%T\%:z");
+
+      gexiv2_metadata_set_tag_string (g2metadata,
+                                      "Xmp.xmp.ModifyDate",
+                                      datetime_buf);
+      gexiv2_metadata_set_tag_string (g2metadata,
+                                      "Xmp.xmp.MetadataDate",
+                                      datetime_buf);
+
       if (! g_strcmp0 (mime_type, "image/tiff"))
         {
           /* TIFF specific XMP data */
@@ -362,17 +373,9 @@ gimp_image_metadata_save_prepare (gint32                 image_ID,
                                           "Xmp.tiff.ImageLength",
                                           buffer);
 
-          g_snprintf (buffer, sizeof (buffer),
-                      "%d:%02d:%02d %02d:%02d:%02d",
-                      g_date_time_get_year (datetime),
-                      g_date_time_get_month (datetime),
-                      g_date_time_get_day_of_month (datetime),
-                      g_date_time_get_hour (datetime),
-                      g_date_time_get_minute (datetime),
-                      g_date_time_get_second (datetime));
           gexiv2_metadata_set_tag_string (g2metadata,
                                           "Xmp.tiff.DateTime",
-                                          buffer);
+                                          datetime_buf);
         }
 
       /* IPTC */
@@ -381,26 +384,7 @@ gimp_image_metadata_save_prepare (gint32                 image_ID,
           ! gexiv2_metadata_has_iptc (g2metadata))
         *suggested_flags &= ~GIMP_METADATA_SAVE_IPTC;
 
-      g_snprintf (buffer, sizeof (buffer),
-                  "%d-%d-%d",
-                  g_date_time_get_year (datetime),
-                  g_date_time_get_month (datetime),
-                  g_date_time_get_day_of_month (datetime));
-      gexiv2_metadata_set_tag_string (g2metadata,
-                                      "Iptc.Application2.DateCreated",
-                                      buffer);
-
-      g_snprintf (buffer, sizeof (buffer),
-                  "%02d:%02d:%02d-%02d:%02d",
-                  g_date_time_get_hour (datetime),
-                  g_date_time_get_minute (datetime),
-                  g_date_time_get_second (datetime),
-                  g_date_time_get_hour (datetime),
-                  g_date_time_get_minute (datetime));
-      gexiv2_metadata_set_tag_string (g2metadata,
-                                      "Iptc.Application2.TimeCreated",
-                                      buffer);
-
+      g_free (datetime_buf);
       g_date_time_unref (datetime);
 
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]