summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-12-30 16:21:41 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-12-30 16:21:41 +0100
commite420e9f3fbd5e758e4a1489766f74030a1b77b88 (patch)
tree0192b01d0eebaca8de1db9ea958f829adf4784c8
parent6a7b5cbbef56fda6c1f3901949b870ee1fd20758 (diff)
downloadcataract-e420e9f3fbd5e758e4a1489766f74030a1b77b88.tar.xz
Optional fallback to IPTC/EXIF captions and comments
-rw-r--r--generators.c46
-rw-r--r--sample/src/CIAF_1/img_1453.jpgbin0 -> 261710 bytes
-rw-r--r--sample/src/CIAF_1/index.xml4
-rw-r--r--sample/src/setup.xml7
-rw-r--r--setup.c5
-rw-r--r--setup.h1
6 files changed, 58 insertions, 5 deletions
diff --git a/generators.c b/generators.c
index 5eb7fde..8c8bc4e 100644
--- a/generators.c
+++ b/generators.c
@@ -588,6 +588,7 @@ write_html_image (TGallerySetup *setup,
int i;
char *s1, *s2, *s3, *s4;
char *imgname, *preload_imgname;
+ char *title, *title_desc;
char *b;
gboolean res;
int level;
@@ -684,18 +685,52 @@ write_html_image (TGallerySetup *setup,
continue;
}
+ /* Get title and description from IPTC/EXIF/JPEG if not defined */
+ title = g_strdup (item->title);
+ title_desc = g_strdup (item->title_description);
+ if (setup->use_iptc_exif && title == NULL && title_desc == NULL) {
+ if (exif->iptc_caption)
+ title = g_strdup (exif->iptc_caption);
+ if (exif->jpeg_comment) {
+ if (! title)
+ title = g_strdup (exif->jpeg_comment);
+ else
+ title_desc = g_strdup (exif->jpeg_comment);
+ }
+ if (exif->exif_imgdesc) {
+ if (! title)
+ title = g_strdup (exif->exif_imgdesc);
+/* if (! title_desc) -- disabled
+ title_desc = g_strdup (exif->exif_imgdesc); */
+ }
+ if (exif->exif_usercomment) {
+ if (! title)
+ title = g_strdup (exif->exif_usercomment);
+ if (! title_desc)
+ title_desc = g_strdup (exif->exif_usercomment);
+ }
+ /* Convert line breaks to be visible in the HTML code */
+ if (title) {
+ str_replace (&title, "\r\n", "<br />", NULL);
+ str_replace (&title, "\n", "<br />", NULL);
+ }
+ if (title_desc) {
+ str_replace (&title_desc, "\r\n", "<br />", NULL);
+ str_replace (&title_desc, "\n", "<br />", NULL);
+ }
+ }
/* Simple placeholders */
if (strstr (b, "<!-- $(FILE_NAME) -->"))
str_replace (&b, "<!-- $(FILE_NAME) -->", imgname, NULL);
- if (strstr (b, "<!-- $(TITLE) -->") && item->title) {
- s1 = g_strdup (item->title);
+ if (strstr (b, "<!-- $(TITLE) -->") && title) {
+ s1 = g_strdup (title);
fix_entities (&s1);
str_replace (&b, "<!-- $(TITLE) -->", s1, NULL);
g_free (s1);
}
- if (strstr (b, "<!-- $(DESCRIPTION) -->") && item->title_description) {
- s1 = g_strdup (item->title_description);
+ if (strstr (b, "<!-- $(DESCRIPTION) -->") && title_desc) {
+ s1 = g_strdup (title_desc);
fix_entities (&s1);
str_replace (&b, "<!-- $(DESCRIPTION) -->", s1, NULL);
g_free (s1);
@@ -711,7 +746,6 @@ write_html_image (TGallerySetup *setup,
g_free (s1);
}
if (strstr (b, "<!-- $(NAV_BAR) -->")) {
-// s1 = g_strconcat (item->title, " (", imgname, ")", NULL);
s1 = g_strdup (imgname);
parent = parent_items;
level = 0;
@@ -882,6 +916,8 @@ write_html_image (TGallerySetup *setup,
break;
}
free (b);
+ if (title) g_free (title);
+ if (title_desc) g_free (title_desc);
}
fclose (fout);
diff --git a/sample/src/CIAF_1/img_1453.jpg b/sample/src/CIAF_1/img_1453.jpg
new file mode 100644
index 0000000..06b549d
--- /dev/null
+++ b/sample/src/CIAF_1/img_1453.jpg
Binary files differ
diff --git a/sample/src/CIAF_1/index.xml b/sample/src/CIAF_1/index.xml
index 3440c74..7e89297 100644
--- a/sample/src/CIAF_1/index.xml
+++ b/sample/src/CIAF_1/index.xml
@@ -83,5 +83,9 @@
<title_description>This item uses supplied thumbnail</title_description>
</item>
+ <item src="img_1453.jpg">
+ <!-- Captions should be retrieved from IPTC/EXIF -->
+ </item>
+
</items>
</gallery>
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index af2bd9e..f4ed85a 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -28,6 +28,13 @@
<border style="border_single" />
<!-- preload next image (allowed values: "yes", "no") default = yes -->
<preload value="yes" />
+
+ <!-- get image title and description from IPTC and EXIF as a fallback -->
+ <!-- if not overriden by <title> and <title_description> tags -->
+ <!-- (allowed values: "yes", "no") default = no -->
+ <!-- titles are retrieved from the following fields (sorted by priority): -->
+ <!-- Iptc.Application2.Caption, Jpeg.Comment, Exif.Image.ImageDescription, Exif.Photo.UserComment -->
+ <use_iptc_exif value="yes" />
</images>
<!-- META tags in html head section -->
diff --git a/setup.c b/setup.c
index 5ad4bb3..42846b5 100644
--- a/setup.c
+++ b/setup.c
@@ -116,6 +116,9 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
s = xml_file_get_node_attribute (xml, "/gallery_setup/images/preload", "value");
setup->preload = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
if (s) g_free (s);
+ s = xml_file_get_node_attribute (xml, "/gallery_setup/images/use_iptc_exif", "value");
+ setup->use_iptc_exif = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */
+ if (s) g_free (s);
xml_parser_close (xml);
@@ -141,6 +144,8 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
printf("setup: meta_author = '%s'\n", setup->meta_author);
printf("setup: meta_description = '%s'\n", setup->meta_description);
printf("setup: meta_keywords = '%s'\n", setup->meta_keywords);
+ printf("setup: preload = %d\n", setup->preload);
+ printf("setup: use_iptc_exif = %d\n", setup->use_iptc_exif);
#endif
return TRUE;
diff --git a/setup.h b/setup.h
index 9ddae04..6f5c55c 100644
--- a/setup.h
+++ b/setup.h
@@ -55,6 +55,7 @@ typedef struct {
char *border_style;
gboolean preload;
+ gboolean use_iptc_exif;
} TGallerySetup;