summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generators.c6
-rw-r--r--jpeg-utils.cpp24
-rw-r--r--jpeg-utils.h7
-rw-r--r--sample/src/setup.xml6
-rw-r--r--setup.c3
-rw-r--r--setup.h1
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><![CDATA[
diff --git a/setup.c b/setup.c
index 97f1e3c..0584130 100644
--- a/setup.c
+++ b/setup.c
@@ -128,6 +128,7 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
if (s) g_free (s);
setup->site_title = xml_file_get_node_attribute (xml, "/gallery_setup/meta/site", "title");
+ setup->add_copyright = xml_file_get_node_value (xml, "/gallery_setup/meta/add_copyright/text()");
xml_parser_close (xml);
@@ -252,6 +253,8 @@ free_setup_data (TGallerySetup *setup)
free (setup->border_style);
if (setup->site_title)
free (setup->site_title);
+ if (setup->add_copyright)
+ free (setup->add_copyright);
free (setup);
setup = NULL;
}
diff --git a/setup.h b/setup.h
index a90f241..4b2592d 100644
--- a/setup.h
+++ b/setup.h
@@ -60,6 +60,7 @@ typedef struct {
gboolean erase_exif_thumbnail;
char *site_title;
+ char *add_copyright;
} TGallerySetup;