From 6f0b21b11f8711ef425069b277a1c743202174a7 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 15 Apr 2012 22:39:24 +0200 Subject: Add HAS_EXIF define This brings a new HAS_EXIF define which is present when EXIF information are available. Templates have been modified to inform user when not available. The test for EXIF metadata presence is fairly basic, we only look for aperture, focal length and exposure time attributes. This might be a subject to change in the future. --- src/generators.c | 5 +++++ src/jpeg-utils.cpp | 35 +++++++++++++++++++++++++++++++++++ src/jpeg-utils.h | 5 +++++ templates/styles.css | 4 ++++ templates/template_picture.html | 12 ++++++++++-- 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/generators.c b/src/generators.c index 1d05eea..5fe87fe 100644 --- a/src/generators.c +++ b/src/generators.c @@ -707,6 +707,11 @@ write_html_image (TGallerySetup *setup, if (exif == NULL) log_error ("write_html_image: error getting exif data from file \"%s\"\n", img_dst); } + /* Test for basic EXIF keys presence */ + if (exif != NULL && exif_has_key (exif, EXIF_APERTURE) && + exif_has_key (exif, EXIF_FOCAL_LENGTH) && + exif_has_key (exif, EXIF_EXPOSURE)) + g_hash_table_replace (defines, g_strdup ("HAS_EXIF"), g_strdup ("")); /* Retrieve image sizes of preview and original image */ get_image_sizes (img_dst, &img_w, &img_h, setup->autorotate); diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp index 031ecc0..389b8e4 100644 --- a/src/jpeg-utils.cpp +++ b/src/jpeg-utils.cpp @@ -197,6 +197,41 @@ get_exif_data_fixed (ExifData *exif, const gchar *key) return get_exif_data (exif, key); } +/* + * Returns TRUE if the image contains the key specified + */ +gboolean +exif_has_key (ExifData *exif, const gchar *key) +{ + g_return_val_if_fail (exif != NULL, FALSE); + g_return_val_if_fail (key != NULL, FALSE); + + try { + if (g_strcmp0 (key, JPEG_COMMENT) == 0) { + return (! exif->image->comment().empty()); + } + + if (g_str_has_prefix (key, "Exif.")) { + Exiv2::ExifData &exifData = exif->image->exifData(); + if (! exifData.empty()) { + return (! exifData[key].toString().empty()); + } + } + + if (g_str_has_prefix (key, "Iptc.")) { + Exiv2::IptcData &iptcData = exif->image->iptcData(); + if (! iptcData.empty()) { + return (! iptcData[key].toString().empty()); + } + } + + return FALSE; + } + catch (...) { + return FALSE; + } +} + static void autorotate_image (MagickWand *magick_wand) diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h index 05a6a49..7cec3a7 100644 --- a/src/jpeg-utils.h +++ b/src/jpeg-utils.h @@ -62,6 +62,11 @@ void exif_data_free (ExifData *data); gchar * get_exif_data (ExifData *exif, const gchar *key); gchar * get_exif_data_fixed (ExifData *exif, const gchar *key); +/* + * Returns TRUE if the image contains the key specified + */ +gboolean exif_has_key (ExifData *exif, const gchar *key); + /* * resize_image: resize image pointed by src and save result to dst diff --git a/templates/styles.css b/templates/styles.css index b96f19f..ea337f9 100644 --- a/templates/styles.css +++ b/templates/styles.css @@ -175,6 +175,10 @@ div.exif td { font-weight: bold; } +div.no_exif { + padding: 1em 0 0 2.6em; + font-size: 80%; +} /****** GENERAL CLASSES ******/ div.position_marker { diff --git a/templates/template_picture.html b/templates/template_picture.html index 07c79ec..d164b6d 100644 --- a/templates/template_picture.html +++ b/templates/template_picture.html @@ -20,7 +20,9 @@ < Previous :: Next > - + + + @@ -45,7 +47,8 @@
:: Show EXIF -- cgit v1.2.3