summaryrefslogtreecommitdiff
path: root/generators.c
diff options
context:
space:
mode:
Diffstat (limited to 'generators.c')
-rw-r--r--generators.c73
1 files changed, 44 insertions, 29 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 */