Quotes are <3

This commit is contained in:
sh+git@codevoid.de 2019-10-26 13:25:55 +00:00
parent c8afadf4cf
commit a8f8a01698
1 changed files with 15 additions and 39 deletions

View File

@ -27,7 +27,7 @@ MORE=1 # trigger next loop
cleanup() { cleanup() {
# DELETE BROKEN IMAGES # DELETE BROKEN IMAGES
printf '%s\n' "Removing incomplete thumbnails." >&2 printf '%s\n' "Removing incomplete thumbnails." >&2
find $THUMB_PATH -name "*_tmp.*" -exec rm -v "{}" \; find "$THUMB_PATH" -name "*_tmp.*" -exec rm -v "{}" \;
exit 1 exit 1
} }
trap cleanup 1 2 3 6 trap cleanup 1 2 3 6
@ -42,11 +42,11 @@ console() { printf '%s\n' "$1" >&2; }
# CALCULATORS # CALCULATORS
get_width_by_height() { get_width_by_height() {
# returns aspect ratio calculated width # returns aspect ratio calculated width
local F=$1 # image file local F="$1" # image file
local TH=$2 # target height local TH="$2" # target height
local WH="$(identify -format ' %w %h ' "$1" | awk '{ printf("%.3f %.3f",$1,$2) }')" local WH="$(identify -format ' %w %h ' "$1" | awk '{ printf("%.3f %.3f",$1,$2) }')"
R="$(printf "$WH" | awk -vTH=$TH '{ printf("%.0f", TH*($1/$2)) }')" local R="$(printf "$WH" | awk -vTH=$TH '{ printf("%.0f", TH*($1/$2)) }')"
printf '%.0f' "$(($R))" printf '%.0f' "$R"
debug "get_width_by_height: FILE=$F TARGET_HEIGHT=$TH FILE_WxH=$WH RET_WIDTH=$R" debug "get_width_by_height: FILE=$F TARGET_HEIGHT=$TH FILE_WxH=$WH RET_WIDTH=$R"
} }
get_height_by_width() { get_height_by_width() {
@ -54,7 +54,7 @@ get_height_by_width() {
local F=$1 # image file local F=$1 # image file
local TW=$2 # target width local TW=$2 # target width
local WH="$(identify -format ' %w %h ' "$1" | awk '{ printf("%.3f %.3f",$1,$2) }')" local WH="$(identify -format ' %w %h ' "$1" | awk '{ printf("%.3f %.3f",$1,$2) }')"
R="$(printf "$WH" | awk -vTW=$TW '{ printf("%.0f", TW*($2/$1)) }')" local R="$(printf "$WH" | awk -vTW=$TW '{ printf("%.0f", TW*($2/$1)) }')"
printf '%.0f' "$R" printf '%.0f' "$R"
debug "get_height_by_width: FILE=$F TARGET_WIDTH=$TW FILE_WxH=$WH RET_HEIGHT=$R" debug "get_height_by_width: FILE=$F TARGET_WIDTH=$TW FILE_WxH=$WH RET_HEIGHT=$R"
} }
@ -90,7 +90,7 @@ create_thumb() {
# ADD IMAGE LOOP # ADD IMAGE LOOP
add_image() { add_image() {
local F=$1 # image file local F="$1" # image file
# How wide would the image be when we rescale it to $ROW_HEIGHT? # How wide would the image be when we rescale it to $ROW_HEIGHT?
local NW=$(get_width_by_height "$F" "$ROW_HEIGHT") local NW=$(get_width_by_height "$F" "$ROW_HEIGHT")
@ -107,7 +107,7 @@ add_image() {
# calculate how much we need to stretch images to fill the # calculate how much we need to stretch images to fill the
# whole row. # whole row.
RFH=$(printf "$G_ROW_WIDTH $WIDTH $ROW_HEIGHT" \ local RFH=$(printf "$G_ROW_WIDTH $WIDTH $ROW_HEIGHT" \
| awk '{ printf("%.0f",$3*($2/$1)) }') | awk '{ printf("%.0f",$3*($2/$1)) }')
debug "RFH=$RFH" debug "RFH=$RFH"
@ -123,11 +123,11 @@ add_image() {
# output HTML for image # output HTML for image
console "Adding Image: $RF" console "Adding Image: $RF"
printf " <div class=\"image\">\n" printf ' <div class="image">\n'
printf " <a href=\"$RF\">\n" printf ' <a href="'$RF'">\n'
printf " <img width=$RFW height=$RFH src=\"$T\">" printf ' <img width="'$RFW'" height="'$RFH'" src="'$T'">'
printf " </a>\n" printf ' </a>\n'
printf " </div>\n" printf ' </div>\n'
done done
# we're done with this row now. # we're done with this row now.
@ -139,7 +139,7 @@ add_image() {
else else
# add more items... # add more items...
debug "add_image: width has not been reached, continue loop." debug "add_image: width has not been reached, continue loop."
G_ROW_WIDTH=$(( $G_ROW_WIDTH + $NW )) G_ROW_WIDTH="$(( $G_ROW_WIDTH + $NW ))"
G_ROW_FILES="$F|$G_ROW_FILES" G_ROW_FILES="$F|$G_ROW_FILES"
fi fi
} }
@ -179,13 +179,12 @@ printf '%s\n' \
<body> <body>
<div class="base"> <div class="base">
' '
### MAIN LOOP ########################################################## ### MAIN LOOP ##########################################################
for F in *.*; for F in *.*;
do do
if [ -f "$F" ]; if [ -f "$F" ];
then then
case $(printf '%s' ${F##*.} | tr '[:upper:]' '[:lower:]') in case "$(printf '%s' ${F##*.} | tr '[:upper:]' '[:lower:]')" in
jpg|jpeg|png|gif) add_image "$F" ;; jpg|jpeg|png|gif) add_image "$F" ;;
*) console "Ignoring: $F" ;; *) console "Ignoring: $F" ;;
esac esac
@ -198,26 +197,3 @@ printf '%s\n' \
' </div> ' </div>
</body> </body>
</html>' </html>'
### MAIN LOOP ##########################################################
#for file in *.*;
#do
# if [ -f "$file" ];
# then
# case $(printf '%s' ${file##*.} | tr '[:upper:]' '[:lower:]') in
# jpg|jpeg|png)
# add_image "$file" "${file%%.*}" "jpeg" ;;
# gif)
# add_image "$file" "${file%%.*}" "gif" ;;
# *) printf '%s\n' "Ignoring: $file" >&2 ;;
# esac
# fi
#done
### MAIN LOOP END ######################################################