From 7f6d35f9b80c8220e226180f946bd7d892421609 Mon Sep 17 00:00:00 2001 From: "sh+git@codevoid.de" Date: Sat, 26 Oct 2019 15:03:06 +0000 Subject: [PATCH] Fix cache file detection --- mkpicindex-static.sh | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mkpicindex-static.sh b/mkpicindex-static.sh index 9addbae..6ce992e 100755 --- a/mkpicindex-static.sh +++ b/mkpicindex-static.sh @@ -16,7 +16,10 @@ ROW_HEIGHT=150 # how high will the justified rows be? THUMB_QUALITY=83 # quality for thumbnails THUMB_PATH="thm" # relative path to thumbnail folder THUMB_PADDING="6" # image padding -DEBUG=$1 # debug output + +# TECHNICAL STUFF +DEBUG=0 # debug output +THREADS=4 # GLOBAL TMP VARIABLES G_ROW_WIDTH=0 # combined pic width < WIDTH @ ROW_HEIGHT @@ -43,9 +46,9 @@ get_width_by_height() { debug "get_width_by_height: FILE=$F TARGET_HEIGHT=$TH FILE_WxH=$WH RET_WIDTH=$R" } # TOO MANY CONVERT PROCSSES => WAIT -bg_check() { - while [ $(pgrep convert | wc -l | awk '{ print $1 }') -gt 4 ]; - do console "More than 4 convert threads. Waiting..."; sleep 2; done +thread_check() { + while [ $(pgrep convert | wc -l | awk '{ print $1 }') -gt $THREADS ]; + do console "More than $THREADS convert threads. Waiting..."; sleep 2; done } # CREATE THUMBNAIL @@ -54,9 +57,12 @@ create_thumb() { local W="$2" # width local H="$3" # height local T="${F%%.*}-$H" - if ! [ -f "$THUMB_PATH/$T.gif" ] && ! [ -f "$THUMB_PATH/$T.jpeg" ]; - bg_check - then + if [ -f "$THUMB_PATH/$T.gif" ]; + then printf '%s' "$THUMB_PATH/$T.gif" + elif [ -f "$THUMB_PATH/$T.jpeg" ]; + then printf '%s' "$THUMB_PATH/$T.jpeg" + else + thread_check case $(printf '%s' "${F##*.}" | tr '[:upper:]' '[:lower:]') in gif) console "Creating Thumbnail: $THUMB_PATH/$T.gif" nohup convert -quality $THUMB_QUALITY -sharpen 2x2 \ @@ -87,7 +93,7 @@ add_image() { debug "add_image: max width reached with F=$F @ $G_ROW_WIDTH" # we're building a row now - printf "
\n"; + printf "
\n"; # calculate how much we need to stretch images to fill the # whole row. @@ -107,15 +113,15 @@ add_image() { # output HTML for image console "Adding Image: $RF" - printf '
\n' - printf ' \n' - printf ' ' - printf ' \n' - printf '
\n' + printf '
\n' + printf ' \n' + printf ' \n' + printf ' \n' + printf '
\n' done # we're done with this row now. - printf "
\n"; + printf "
\n"; # set leftover file as for next iteration G_ROW_WIDTH="$NW"