summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sample/src/setup.xml7
-rw-r--r--src/generators.c17
-rw-r--r--src/jpeg-utils.cpp32
-rw-r--r--src/jpeg-utils.h6
-rw-r--r--src/setup.c8
-rw-r--r--src/setup.h7
-rw-r--r--templates/styles.css23
-rw-r--r--templates/template-album.tmpl13
-rw-r--r--templates/template-index.tmpl15
-rw-r--r--templates/template-view_photo.tmpl1
10 files changed, 113 insertions, 16 deletions
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index 80d04da..72ce9dd 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -34,6 +34,7 @@
<!-- default sizes of thumbnail and preview images -->
<thumbnail landscape_w="180" landscape_h="120"
portrait_w="120" portrait_h="180"
+ square="180"
quality="80" />
<preview landscape_w="900" landscape_h="600"
portrait_w="500" portrait_h="750"
@@ -70,6 +71,12 @@
<!-- %d is optional, denotes item index in the album -->
<!-- this also avoids conflicts with identical names -->
<thumbnail_name_format>thn_%d_%s</thumbnail_name_format>
+
+ <!-- Make thumbnails squared, crop in different ways: -->
+ <!-- none - no squared thumbnails, retain previous behaviour (default) -->
+ <!-- simple - crop from center, shave 5% from borders -->
+ <!-- ... more to come! (looking for a fast and clever algorithm) -->
+ <squared_thumbnails type="none" />
</images>
<meta>
diff --git a/src/generators.c b/src/generators.c
index f0ba940..cf32819 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -171,11 +171,17 @@ generate_image (TGallerySetup *setup,
*thumb_portrait = (thumb_w / thumb_h) < 1;
if ((thumb_w > 0) && (thumb_h > 0)) {
+ /* Squared thumbnails */
+ if (setup->squared_thumbnail_type != THUMBNAIL_SQUARE_TYPE_NONE) {
+ thumb_w = setup->thumbnail_square_size;
+ thumb_h = setup->thumbnail_square_size;
+ } else
+ /* Portrait / Landscape thumbnails */
if (! *thumb_portrait)
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, TRUE))
+ if (! resize_image (thumb_src_full, thumb_dst, thumb_w, thumb_h, setup->thumbnail_quality, TRUE, setup->squared_thumbnail_type))
log_error ("generate_image: error resizing thumbnail %s\n", thumb_src_full);
} else
log_error ("generate_image: thumbnail %s sizes are %lux%lu\n", thumb_src_full, thumb_w, thumb_h);
@@ -208,7 +214,7 @@ generate_image (TGallerySetup *setup,
}
g_assert (img_src_full != NULL);
- if (! resize_image (img_src_full, big_dst, new_w, new_h, bigq, FALSE))
+ if (! resize_image (img_src_full, big_dst, new_w, new_h, bigq, FALSE, 0))
log_error ("generate_image: error resizing big image %s\n", img_src_full);
}
else
@@ -413,6 +419,7 @@ write_html_album (TGallerySetup *setup,
block_parser_register_key (block_parser, "IMG_LIST", "IMG_LIST");
block_parser_register_key (block_parser, "IMG_LIST_LANDSCAPE", NULL);
block_parser_register_key (block_parser, "IMG_LIST_PORTRAIT", NULL);
+ block_parser_register_key (block_parser, "IMG_LIST_SQUARED", NULL);
block_parser_register_key (block_parser, "LIST_SEPARATOR", NULL);
block_parser_register_key (block_parser, "LIST_INTERSPACE", NULL);
block_parser_register_key (block_parser, "GO_UP", "GO_UP");
@@ -454,7 +461,11 @@ write_html_album (TGallerySetup *setup,
case INDEX_ITEM_TYPE_PICTURE:
/* Skip HTML code generation if it's a hidden item */
if (! item->hidden) {
- s1 = block_parser_get_data (block_parser, item->gen_portrait ? "IMG_LIST_PORTRAIT" : "IMG_LIST_LANDSCAPE");
+ if (setup->squared_thumbnail_type != THUMBNAIL_SQUARE_TYPE_NONE)
+ s1 = "IMG_LIST_SQUARED";
+ else
+ s1 = item->gen_portrait ? "IMG_LIST_PORTRAIT" : "IMG_LIST_LANDSCAPE";
+ s1 = block_parser_get_data (block_parser, s1);
replace_table_add_key_printf (local_replace_table, "ALBUM_SUBPATH", "%s/%s", item->path, setup->index_file_name);
s3 = item_get_img_src (setup, items, item);
replace_table_add_key_printf (local_replace_table, "IMG_SUBPAGE", "%s%s", s3, GET_EXT (setup->index_file_name));
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp
index 3bde7b6..d46e064 100644
--- a/src/jpeg-utils.cpp
+++ b/src/jpeg-utils.cpp
@@ -231,9 +231,10 @@ free_exif_data (TExifData *data)
*/
gboolean
resize_image (const gchar *src, const gchar *dst,
- int size_x, int size_y,
- int quality,
- gboolean thumbnail)
+ int size_x, int size_y,
+ int quality,
+ gboolean thumbnail,
+ ThumbnailSquareType squared_thumbnail_type)
{
#define ThrowWandException(wand) \
{ \
@@ -248,14 +249,35 @@ resize_image (const gchar *src, const gchar *dst,
MagickBooleanType status;
MagickWand *magick_wand;
+ unsigned long w;
+ unsigned long h;
+ unsigned long amount;
/* Read an image. */
magick_wand = NewMagickWand();
status = MagickReadImage (magick_wand, src);
if (status == MagickFalse)
- ThrowWandException (magick_wand);
- if (thumbnail)
+ ThrowWandException (magick_wand);
+
+ /* Process thumbnail if required */
+ if (thumbnail) {
+ switch (squared_thumbnail_type) {
+ case THUMBNAIL_SQUARE_TYPE_SIMPLE:
+ w = MagickGetImageWidth (magick_wand);
+ h = MagickGetImageHeight (magick_wand);
+ amount = MAX (w, h) * SQUARED_SIMPLE_SHAVE_AMOUNT / 100;
+ MagickShaveImage (magick_wand, amount, amount);
+
+ w = MagickGetImageWidth (magick_wand);
+ h = MagickGetImageHeight (magick_wand);
+ amount = MIN (w, h);
+ MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
+ break;
+ default:
+ break;
+ }
MagickThumbnailImage (magick_wand, size_x, size_y);
+ }
else
MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0);
MagickSetImageCompressionQuality (magick_wand, quality);
diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h
index 65e97c5..e31ed52 100644
--- a/src/jpeg-utils.h
+++ b/src/jpeg-utils.h
@@ -21,6 +21,9 @@
#endif
#include <glib.h>
+#include "setup.h"
+
+#define SQUARED_SIMPLE_SHAVE_AMOUNT 5 /* percent */
/* TODO: we want to have numerical values here at some point in the future */
@@ -68,7 +71,8 @@ void free_exif_data (TExifData *data);
gboolean resize_image (const gchar *src, const gchar *dst,
int size_x, int size_y,
int quality,
- gboolean thumbnail);
+ gboolean thumbnail,
+ ThumbnailSquareType squared_thumbnail_type);
/*
* get_image_sizes: retrieve image dimensions
diff --git a/src/setup.c b/src/setup.c
index 6d3c6be..daa1ff0 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -123,6 +123,7 @@ parse_setup_xml (const gchar *filename, TGallerySetup *setup)
setup->thumbnail_landscape_height = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_h", 0);
setup->thumbnail_portrait_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "portrait_w", 0);
setup->thumbnail_portrait_height = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "portrait_h", 0);
+ setup->thumbnail_square_size = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "square", 0);
setup->thumbnail_quality = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "quality", -1);
setup->preview_landscape_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/preview", "landscape_w", 0);
setup->preview_landscape_height = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/preview", "landscape_h", 0);
@@ -157,6 +158,13 @@ parse_setup_xml (const gchar *filename, TGallerySetup *setup)
setup->feed_title = xml_file_get_node_value (xml, "/gallery_setup/feed/title/text()");
setup->feed_base_url = xml_file_get_node_value (xml, "/gallery_setup/feed/base_url/text()");
+ s = xml_file_get_node_attribute (xml, "/gallery_setup/images/squared_thumbnails", "type");
+ if (s && g_ascii_strcasecmp (s, "simple") == 0)
+ setup->squared_thumbnail_type = THUMBNAIL_SQUARE_TYPE_SIMPLE;
+ else
+ setup->squared_thumbnail_type = THUMBNAIL_SQUARE_TYPE_NONE;
+ g_free (s);
+
xml_parser_close (xml);
return TRUE;
}
diff --git a/src/setup.h b/src/setup.h
index 8c9927f..16665c4 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -32,6 +32,11 @@
#define DEFAULT_INDEX_FILENAME "index.html"
+typedef enum {
+ THUMBNAIL_SQUARE_TYPE_NONE,
+ THUMBNAIL_SQUARE_TYPE_SIMPLE
+} ThumbnailSquareType;
+
/* Global gallery setup */
typedef struct {
@@ -52,6 +57,7 @@ typedef struct {
gchar *img_big_dir;
gchar *img_orig_dir;
gchar *thumbnail_name_format;
+ ThumbnailSquareType squared_thumbnail_type;
gchar *footer;
gchar *meta_author;
@@ -65,6 +71,7 @@ typedef struct {
unsigned long thumbnail_landscape_height;
unsigned long thumbnail_portrait_width;
unsigned long thumbnail_portrait_height;
+ unsigned long thumbnail_square_size;
int preview_quality;
unsigned long preview_landscape_width;
diff --git a/templates/styles.css b/templates/styles.css
index 0a42f53..8c3aaf2 100644
--- a/templates/styles.css
+++ b/templates/styles.css
@@ -222,6 +222,11 @@ div.album_item img.portrait {
padding-top: 1em;
}
+div.album_item img.squared {
+ /* squared */
+ padding-top: 1em;
+}
+
.album_thumb_text {
/* CSS positioning sucks^2 */
position: absolute;
@@ -347,6 +352,16 @@ div.index_item img {
/* padding-right: 7.7em; disabled -- word wrap */
top: 0.65em;
}
+
+.album_text_squared {
+ font-size: 190%;
+ font-weight: bold;
+ position: relative;
+ left: 10.3em;
+/* padding-right: 10.5em; disabled -- word wrap */
+ top: 0.65em;
+}
+
.album_subtext {
font-size: 150%;
position: relative;
@@ -363,6 +378,14 @@ div.index_item img {
top: 2.5em;
}
+.album_subtext_squared {
+ font-size: 150%;
+ position: relative;
+ left: 13.1em;
+/* padding-right: 13.4em; disabled -- word wrap */
+ top: 2.5em;
+}
+
.album_note {
position: absolute;
right: 2.3em;
diff --git a/templates/template-album.tmpl b/templates/template-album.tmpl
index c018057..aaff9ef 100644
--- a/templates/template-album.tmpl
+++ b/templates/template-album.tmpl
@@ -40,7 +40,7 @@
<img src="$(IMG_THUMBNAIL)" alt="$(IMG_TITLE)" />
<span class="album_thumb_text"><!-- $(IMG_FILENAME) --></span>
</a>
- </div>
+ </div>
<!-- $(END_IMG_LIST_LANDSCAPE) -->
<!-- $(BEGIN_IMG_LIST_PORTRAIT) -->
<div class="album_item" id="$(IMG_LIST_ID)">
@@ -48,8 +48,16 @@
<img src="$(IMG_THUMBNAIL)" alt="$(IMG_TITLE)" class="portrait" />
<span class="album_thumb_text"><!-- $(IMG_FILENAME) --></span>
</a>
- </div>
+ </div>
<!-- $(END_IMG_LIST_PORTRAIT) -->
+ <!-- $(BEGIN_IMG_LIST_SQUARED) -->
+ <div class="album_item" id="$(IMG_LIST_ID)">
+ <a href="$(IMG_SUBPAGE)">
+ <img src="$(IMG_THUMBNAIL)" alt="$(IMG_TITLE)" class="squared" />
+ <span class="album_thumb_text"><!-- $(IMG_FILENAME) --></span>
+ </a>
+ </div>
+ <!-- $(END_IMG_LIST_SQUARED) -->
<!-- $(BEGIN_LIST_SEPARATOR) -->
<div class="separators">
<div class="index_separator"><!-- $(LIST_SEPARATOR_TITLE) --></div>
@@ -75,4 +83,3 @@
</body>
</html>
-
diff --git a/templates/template-index.tmpl b/templates/template-index.tmpl
index b2c7dba..77504e7 100644
--- a/templates/template-index.tmpl
+++ b/templates/template-index.tmpl
@@ -42,7 +42,7 @@
<span class="album_subtext"><!-- $(IMG_DESCRIPTION) --></span>
<span class="album_note">(<!-- $(ALBUM_NUM_ITEMS) --> items)</span>
</a>
- </div>
+ </div>
<!-- $(END_IMG_LIST_LANDSCAPE) -->
<!-- $(BEGIN_IMG_LIST_PORTRAIT) -->
<div class="index_item" id="$(IMG_LIST_ID)">
@@ -52,8 +52,18 @@
<span class="album_subtext_portrait"><!-- $(IMG_DESCRIPTION) --></span>
<span class="album_note">(<!-- $(ALBUM_NUM_ITEMS) --> items)</span>
</a>
- </div>
+ </div>
<!-- $(END_IMG_LIST_PORTRAIT) -->
+ <!-- $(BEGIN_IMG_LIST_SQUARED) -->
+ <div class="index_item" id="$(IMG_LIST_ID)">
+ <a href="$(ALBUM_SUBPATH)">
+ <img src="$(IMG_THUMBNAIL)" alt="" />
+ <span class="album_text_squared"><!-- $(IMG_TITLE) --></span><br />
+ <span class="album_subtext_squared"><!-- $(IMG_DESCRIPTION) --></span>
+ <span class="album_note">(<!-- $(ALBUM_NUM_ITEMS) --> items)</span>
+ </a>
+ </div>
+ <!-- $(END_IMG_LIST_SQUARED) -->
<!-- $(BEGIN_LIST_SEPARATOR) -->
<div class="separators">
<div class="album_list_separator"><!-- $(LIST_SEPARATOR_TITLE) --></div>
@@ -79,4 +89,3 @@
</body>
</html>
-
diff --git a/templates/template-view_photo.tmpl b/templates/template-view_photo.tmpl
index 7fe58e2..7557846 100644
--- a/templates/template-view_photo.tmpl
+++ b/templates/template-view_photo.tmpl
@@ -74,4 +74,3 @@
</body>
</html>
-