summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-08-10 16:31:23 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-08-10 16:31:23 +0200
commite291c5c25b81c9e944523227ea55f7f96e2472ca (patch)
tree2e6a9fd21517d961c51eba2bde1b9f89f8d57c4b
parent7f74efd63d8026e1d11d33aa9f3b236127bb89dc (diff)
downloadcataract-e291c5c25b81c9e944523227ea55f7f96e2472ca.tar.xz
Support for supplied thumbnails
(useful if you have framed preview and original images and want to have non-framed thumbnails)
-rw-r--r--generators.c73
-rw-r--r--items.c10
-rw-r--r--sample/src/CIAF_1/index.xml5
l---------sample/src/CIAF_1/preview/img_6802g.jpg1
-rw-r--r--sample/src/CIAF_1/thumbnails/gallery_thumbnails.gifbin0 -> 729 bytes
5 files changed, 57 insertions, 32 deletions
diff --git a/generators.c b/generators.c
index 210bdb0..3411b8f 100644
--- a/generators.c
+++ b/generators.c
@@ -33,6 +33,7 @@
/*
* generate_image: auxiliary function for write_html_album
+ * - img_src and thumb should be freed afterwards
*/
void
generate_image (TGallerySetup *setup,
@@ -40,60 +41,69 @@ generate_image (TGallerySetup *setup,
TIndexItem *item,
const char *dst,
unsigned long *img_w, unsigned long *img_h,
- const char **img_src)
+ char **img_src, char **thumb)
{
unsigned long new_w, new_h;
+ unsigned long thumb_w, thumb_h;
char *thumb_dst;
char *big_dst;
char *big_src;
char *orig_dst;
char *img_src_full;
- char *s1, *s2;
+ char *thumb_src_full;
+ char *s1;
int bigq;
- *img_src = item->thumbnail;
- if (items->type == GALLERY_TYPE_INDEX)
- *img_src = item->thumbnail;
+ if (items->type == GALLERY_TYPE_INDEX) {
+ img_src_full = g_strconcat (items->base_dir, "/", item->thumbnail, NULL);
+ thumb_src_full = g_strconcat (items->base_dir, "/", item->thumbnail, NULL);
+ *img_src = g_path_get_basename (item->thumbnail);
+ *thumb = g_path_get_basename (item->thumbnail);
+ }
else
- if (items->type == GALLERY_TYPE_ALBUM)
+ if (items->type == GALLERY_TYPE_ALBUM) {
*img_src = (item->path == NULL && item->preview) ? item->preview : item->path;
+ *thumb = (item->thumbnail) ? item->thumbnail : *img_src;
+ img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL);
+ thumb_src_full = g_strconcat (items->base_dir, "/", *thumb, NULL);
+ *img_src = g_path_get_basename (*img_src);
+ *thumb = g_path_get_basename (*thumb);
+ }
- img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL);
get_image_sizes (img_src_full, img_w, img_h);
if ((img_w > 0) && (img_h > 0)) {
new_w = *img_w;
new_h = *img_h;
-
/* Generate thumbnail */
+ get_image_sizes (thumb_src_full, &thumb_w, &thumb_h);
s1 = g_path_get_dirname (dst);
- s2 = g_path_get_basename (*img_src);
- thumb_dst = g_strconcat (s1, "/", THUMBNAIL_DIR, "/", s2, NULL);
+ thumb_dst = g_strconcat (s1, "/", THUMBNAIL_DIR, "/", *thumb, NULL);
g_free (s1);
- g_free (s2);
- if (setup->verbose) printf (" Generating thumbnail of '%s' ...", *img_src);
+ if (setup->verbose) printf (" Generating thumbnail of '%s' ...", *thumb);
- if ((*img_w / *img_h) >= 1)
- calculate_sizes (setup->thumbnail_landscape_width, setup->thumbnail_landscape_height, &new_w, &new_h);
- else
- calculate_sizes (setup->thumbnail_portrait_width, setup->thumbnail_portrait_height, &new_w, &new_h);
- if (! resize_image (img_src_full, thumb_dst, new_w, new_h, setup->thumbnail_quality))
- fprintf (stderr, "write_html_index: error resizing thumbnail %s\n", img_src_full);
- else
- if (setup->verbose) printf (" done.\n");
- g_free (thumb_dst);
+ if ((thumb_w > 0) && (thumb_h > 0)) {
+ if ((thumb_w / thumb_h) >= 1)
+ calculate_sizes (setup->thumbnail_landscape_width, setup->thumbnail_landscape_height, &thumb_w, &thumb_h);
+ else
+ calculate_sizes (setup->thumbnail_portrait_width, setup->thumbnail_portrait_height, &thumb_w, &thumb_h);
+ if (! resize_image (thumb_src_full, thumb_dst, thumb_w, thumb_h, setup->thumbnail_quality))
+ fprintf (stderr, "write_html_index: error resizing thumbnail %s\n", thumb_src_full);
+ else
+ if (setup->verbose) printf (" done.\n");
+ g_free (thumb_dst);
+ } else
+ printf (" failed!\n");
/* Generate/copy preview and original image */
if (items->type == GALLERY_TYPE_ALBUM)
{
s1 = g_path_get_dirname (dst);
- s2 = g_path_get_basename (*img_src);
- big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", s2, NULL);
+ big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", *img_src, NULL);
g_free (s1);
- g_free (s2);
if (item->preview == NULL) {
/* No preview image supplied, generate it from original */
@@ -158,6 +168,7 @@ generate_image (TGallerySetup *setup,
}
}
g_free (img_src_full);
+ g_free (thumb_src_full);
}
@@ -195,7 +206,8 @@ write_html_album (TGallerySetup *setup,
gboolean res;
int i;
unsigned long img_w, img_h;
- const char *img_src;
+ char *img_src;
+ char *thumb;
fin = fopen (template_src, "r");
@@ -365,7 +377,8 @@ write_html_album (TGallerySetup *setup,
img_w = 0;
img_h = 0;
img_src = NULL;
- generate_image (setup, items, item, dst, &img_w, &img_h, &img_src);
+ thumb = NULL;
+ generate_image (setup, items, item, dst, &img_w, &img_h, &img_src, &thumb);
/* Process HTML box code */
if ((img_w / img_h) >= 1)
@@ -403,11 +416,9 @@ write_html_album (TGallerySetup *setup,
g_free (s3);
}
if (strstr (s1, "<!-- $(IMG_THUMBNAIL) -->")) {
- s3 = g_path_get_basename (img_src);
- s2 = g_strconcat (THUMBNAIL_DIR, "/", s3, NULL);
+ s2 = g_strconcat (THUMBNAIL_DIR, "/", thumb, NULL);
str_replace (&s1, "<!-- $(IMG_THUMBNAIL) -->", s2, NULL);
g_free (s2);
- g_free (s3);
}
if (strstr (s1, "<!-- $(IMG_FILENAME) -->"))
str_replace (&s1, "<!-- $(IMG_FILENAME) -->", img_src, NULL);
@@ -423,6 +434,10 @@ write_html_album (TGallerySetup *setup,
break;
}
free (s1);
+ if (img_src)
+ g_free (img_src);
+ if (thumb)
+ g_free (thumb);
}
free (b);
continue; /* no need to write anything */
diff --git a/items.c b/items.c
index 91eee63..77f051f 100644
--- a/items.c
+++ b/items.c
@@ -101,6 +101,8 @@ parse_album_xml (const char *filename, TAlbum *index)
item->width = xml_file_get_node_attribute_long (xml, s, "width", 0);
item->height = xml_file_get_node_attribute_long (xml, s, "height", 0);
item->border_style = xml_file_get_node_attribute (xml, s, "border");
+ if (index->type == GALLERY_TYPE_ALBUM)
+ item->thumbnail = xml_file_get_node_attribute (xml, s, "thumbnail");
g_free (s);
s = g_strdup_printf ("/gallery/items/item[%d]/title/text()", i + 1);
@@ -111,9 +113,11 @@ parse_album_xml (const char *filename, TAlbum *index)
item->title_description = xml_file_get_node_value (xml, s);
g_free (s);
- s = g_strdup_printf ("/gallery/items/item[%d]/thumbnail", i + 1);
- item->thumbnail = xml_file_get_node_attribute (xml, s, "src");
- g_free (s);
+ if (index->type == GALLERY_TYPE_INDEX) {
+ s = g_strdup_printf ("/gallery/items/item[%d]/thumbnail", i + 1);
+ item->thumbnail = xml_file_get_node_attribute (xml, s, "src");
+ g_free (s);
+ }
s = g_strdup_printf ("/gallery/items/item[%d]/nofullsize", i + 1);
item->nofullsize = (xml_file_get_node_present (xml, s) || item->path == NULL);
diff --git a/sample/src/CIAF_1/index.xml b/sample/src/CIAF_1/index.xml
index fe98cc2..ed374a0 100644
--- a/sample/src/CIAF_1/index.xml
+++ b/sample/src/CIAF_1/index.xml
@@ -68,5 +68,10 @@
<title_description>This particular image overrides both global and album border styles.</title_description>
</item>
+ <item preview="preview/img_6802g.jpg" thumbnail="thumbnails/gallery_thumbnails.gif">
+ <title>Custom thumbnail</title>
+ <title_description>This item uses supplied thumbnail</title_description>
+ </item>
+
</items>
</gallery>
diff --git a/sample/src/CIAF_1/preview/img_6802g.jpg b/sample/src/CIAF_1/preview/img_6802g.jpg
new file mode 120000
index 0000000..d6b7d1d
--- /dev/null
+++ b/sample/src/CIAF_1/preview/img_6802g.jpg
@@ -0,0 +1 @@
+img_6802.jpg \ No newline at end of file
diff --git a/sample/src/CIAF_1/thumbnails/gallery_thumbnails.gif b/sample/src/CIAF_1/thumbnails/gallery_thumbnails.gif
new file mode 100644
index 0000000..4c35c6c
--- /dev/null
+++ b/sample/src/CIAF_1/thumbnails/gallery_thumbnails.gif
Binary files differ