From ce1ae1ff69309ec7f1905e928a9d43eb8ae86dbe Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Mon, 26 Sep 2016 14:56:06 +0200 Subject: jpeg-utils: Add support for custom resize options This change brings the possibility to tweak resize options using standard ImageMagick `convert` command syntax. Separate options are offered for thumbnails. --- src/gallery-utils.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/gallery-utils.c') diff --git a/src/gallery-utils.c b/src/gallery-utils.c index d97cef3..403b3c6 100644 --- a/src/gallery-utils.c +++ b/src/gallery-utils.c @@ -93,6 +93,40 @@ str_replace (gchar **dst, const gchar *search, const gchar *replace) } +/* + * str_trim_inside: trims any leading, trailing and repeated whitespaces in the whole string + */ +#define IS_WHITESPACE(s) (s == ' ' || s == '\t') + +void +str_trim_inside (gchar **s) +{ + gchar *dst; + gboolean was_whitespace; + int pos; + gchar *src; + + if (! s || strlen (*s) == 0 ) + return; + + /* suppose the new string is not longer than the input string */ + dst = g_malloc0 (strlen (*s) + 1); + was_whitespace = TRUE; /* handles beginning of the string */ + pos = 0; + for (src = *s; *src != '\0'; src++) + if (! IS_WHITESPACE (*src) || ! was_whitespace) { + dst[pos++] = *src; + was_whitespace = IS_WHITESPACE (*src); + } + if (IS_WHITESPACE (dst[pos - 1])) + dst[pos - 1] = '\0'; + + /* return fixed string */ + g_free (*s); + *s = dst; +} + + /* * copy_file: copy file from src to dst */ -- cgit v1.2.3