From 62d52b597d6a9cf4ed7ef0782fad8ca5eca24aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Mon, 29 Nov 2021 21:09:33 +0300 Subject: config: blur setting for thumbnails/images --- README.md | 2 +- include/config.h | 1 + src/config.c | 14 ++++++++++++++ src/site.c | 9 ++++----- src/tests/config.c | 7 +++++-- tests/site.ini | 2 ++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1bf6ac0..9d8e76c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A static web image gallery generator. It optimizes images for the web and generates HTML files to create a photo/image gallery web site ready to be served by an HTML server. -Early stages. It's functional but a little rough around the edges. +Alpha stages. It's functional but a little rough around the edges. ## Building diff --git a/include/config.h b/include/config.h index 398160b..589671f 100644 --- a/include/config.h +++ b/include/config.h @@ -13,6 +13,7 @@ struct image_config { size_t max_width; size_t max_height; bool smart_resize; + double blur; }; struct site_config { diff --git a/src/config.c b/src/config.c index e9dd609..1bc531f 100644 --- a/src/config.c +++ b/src/config.c @@ -75,6 +75,18 @@ site_config_images_keyvalue_handler(struct parcini_line *parsed, res = parcini_value_handle(&parsed->value, PARCINI_VALUE_BOOLEAN, &iconfig->smart_resize) ? CONFIG_KEY_OK : CONFIG_KEY_BADVALUE; } + if (!strcmp(parsed->key, "blur")) { + long int temp; + res = parcini_value_handle(&parsed->value, PARCINI_VALUE_INTEGER, + &temp) ? CONFIG_KEY_OK : CONFIG_KEY_BADVALUE; + if (res == CONFIG_KEY_OK) { + if (temp < -100 || temp > 100) { + res = CONFIG_KEY_BADVALUE; + } else { + iconfig->blur = (double)temp/100; + } + } + } return res; } @@ -227,6 +239,7 @@ site_config_init(void) .max_width = 3000, .max_height = 2000, .smart_resize = true, + .blur = 0, }; config->thumbnails = (struct image_config) { .strip = true, @@ -234,6 +247,7 @@ site_config_init(void) .max_width = 400, .max_height = 270, .smart_resize = true, + .blur = 0.25, }; } diff --git a/src/site.c b/src/site.c index a47d16e..2d3922b 100644 --- a/src/site.c +++ b/src/site.c @@ -111,7 +111,8 @@ optimize_image(MagickWand *wand, const char *dst, nx = ny * ratio; } } - TRYWAND(wand, MagickResizeImage(wand, nx, ny, GaussianFilter, 0)); + TRYWAND(wand, MagickResizeImage(wand, nx, ny, GaussianFilter, + conf->blur)); } TRYWAND(wand, MagickWriteImage(wand, dst)); setdatetime(dst, srcmtim); @@ -214,8 +215,8 @@ albums_walk(struct bstnode *node, void *data) struct stat dstat; if (!nmkdir(album->slug, &dstat, site->dry_run)) return false; + hashmap_insert(site->album_dirs, album->slug, (char *)album->slug); if (!site->dry_run) { - hashmap_insert(site->album_dirs, album->slug, (char *)album->slug); if (!render_set_album_vars(&site->render, album)) return false; } @@ -390,9 +391,7 @@ site_init(struct site *site) site->rel_content_dir = strlen(site->root_dir) + 1; InitializeMagick(NULL); site->wand = NewMagickWand(); - if (!site->dry_run) { - site->album_dirs = hashmap_new(); - } + site->album_dirs = hashmap_new(); site->render.dry_run = site->dry_run; return true; diff --git a/src/tests/config.c b/src/tests/config.c index 8d86a2f..64a4da8 100644 --- a/src/tests/config.c +++ b/src/tests/config.c @@ -1,8 +1,9 @@ #include +#include -#include "tests/tests.h" -#include "config.h" #include "log.h" +#include "config.h" +#include "tests/tests.h" #define TESTS_DIR "tests" #define TEST_ALBUM "tests/album.ini" @@ -20,11 +21,13 @@ test_site_config_read_ini(void) asserteq(config->images.max_width, 3000); asserteq(config->images.max_height, 2000); asserteq(config->images.smart_resize, true); + asserteq(fabs(config->images.blur - 0.0) < 0.0001, true); asserteq(config->thumbnails.strip, true); asserteq(config->thumbnails.quality, 75); asserteq(config->thumbnails.max_width, 400); asserteq(config->thumbnails.max_height, 270); asserteq(config->thumbnails.smart_resize, true); + asserteq(fabs(config->thumbnails.blur - 0.1) < 0.0001, true); site_config_destroy(config); } diff --git a/tests/site.ini b/tests/site.ini index eca9e59..ad4a575 100644 --- a/tests/site.ini +++ b/tests/site.ini @@ -8,6 +8,7 @@ quality = 80 max_width = 3000 max_height = 2000 smart_resize = yes +blur = 0 [thumbnails] strip = yes @@ -15,3 +16,4 @@ quality = 75 max_width = 400 max_height = 270 smart_resize = yes +blur = 10 -- cgit v1.2.3