diff options
| -rw-r--r-- | generators.c | 6 | ||||
| -rw-r--r-- | jpeg-utils.cpp | 24 | ||||
| -rw-r--r-- | jpeg-utils.h | 7 | ||||
| -rw-r--r-- | sample/src/setup.xml | 6 | ||||
| -rw-r--r-- | setup.c | 3 | ||||
| -rw-r--r-- | setup.h | 1 |
6 files changed, 33 insertions, 14 deletions
diff --git a/generators.c b/generators.c index d4b0cf9..4e36648 100644 --- a/generators.c +++ b/generators.c @@ -163,8 +163,7 @@ generate_image (TGallerySetup *setup, if (setup->verbose) printf (" done.\n"); g_free (big_src); } - if (setup->erase_exif_thumbnail) - strip_thumbnail (big_dst); + modify_exif (big_dst, setup->erase_exif_thumbnail, setup->add_copyright); g_free (big_dst); if (! item->nofullsize) @@ -177,8 +176,7 @@ generate_image (TGallerySetup *setup, fprintf (stderr, "write_html_index: error copying original image %s\n", img_src_full); else if (setup->verbose) printf(" done.\n"); - if (setup->erase_exif_thumbnail) - strip_thumbnail (orig_dst); + modify_exif (orig_dst, setup->erase_exif_thumbnail, setup->add_copyright); g_free (orig_dst); } } diff --git a/jpeg-utils.cpp b/jpeg-utils.cpp index cb06abc..c884ef4 100644 --- a/jpeg-utils.cpp +++ b/jpeg-utils.cpp @@ -377,11 +377,17 @@ calculate_sizes (const unsigned long max_width, const unsigned long max_height, /* - * strip_thumbnail: strip thumbnail stored in EXIF table + * modify_exif: - strip thumbnail stored in EXIF table + * - add copyright to Exif::Image::Copyright and Iptc::Application2::Copyright */ void -strip_thumbnail (const char *filename) +modify_exif (const char *filename, gboolean strip_thumbnail, const char *add_copyright) { + bool was_modified = false; + + if ((! strip_thumbnail) && (add_copyright == NULL)) + return; + try { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename); @@ -389,17 +395,23 @@ strip_thumbnail (const char *filename) image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); - if (! exifData.empty()) { + if (add_copyright) { + exifData["Exif.Image.Copyright"] = add_copyright; + image->iptcData()["Iptc.Application2.Copyright"] = add_copyright; + was_modified = true; + } + if (strip_thumbnail && (! exifData.empty())) { std::string thumbExt = exifData.thumbnailExtension(); if (! thumbExt.empty()) { exifData.eraseThumbnail(); - image->writeMetadata(); + was_modified = true; } } + if (was_modified) + image->writeMetadata(); } catch (Exiv2::AnyError& e) { - fprintf (stderr, "strip_thumbnail: Caught Exiv2 exception: '%s'\n", e.what()); + fprintf (stderr, "modify_exif: Caught Exiv2 exception: '%s'\n", e.what()); } } - diff --git a/jpeg-utils.h b/jpeg-utils.h index 7d05eab..9b8919f 100644 --- a/jpeg-utils.h +++ b/jpeg-utils.h @@ -76,7 +76,6 @@ gboolean resize_image (const char *src, const char *dst, void get_image_sizes (const char *img, unsigned long *width, unsigned long *height); - /* * calculate_sizes: calculate maximal image sizes within specified limits keeping aspect ratio */ @@ -84,10 +83,10 @@ void calculate_sizes (const unsigned long max_width, const unsigned long max_hei unsigned long *width, unsigned long *height); /* - * strip_thumbnail: strip thumbnail stored in EXIF table + * modify_exif: - strip thumbnail stored in EXIF table + * - add copyright to Exif::Image::Copyright and Iptc::Application2::Copyright */ -void strip_thumbnail (const char *filename); - +void modify_exif (const char *filename, gboolean strip_thumbnail, const char *add_copyright); #ifdef __cplusplus diff --git a/sample/src/setup.xml b/sample/src/setup.xml index 2ebf0d0..22c6823 100644 --- a/sample/src/setup.xml +++ b/sample/src/setup.xml @@ -57,6 +57,12 @@ <!-- mandatory site name, part of all page titles --> <site title="CGG Testing Site" /> + + <!-- add your copyright string to every picture --> + <!-- stored in EXIF::Image::Copyright and IPTC::Application2::Copyright --> + <!-- usual format: "Copyright, John Smith, 19xx. All rights reserved." --> + <add_copyright>This is custom copyright string added to every picture. +And the second line.</add_copyright> </meta> <footer><