From fd9d8539e1c3a284581071af9ea88288d5dc7a5b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 17 Sep 2015 02:56:20 +0300 Subject: [PATCH] added support for smaller than target previews... Signed-off-by: Alex A. Naanou --- scripts/process-archive.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/process-archive.sh b/scripts/process-archive.sh index c3270ad2..ed36318d 100755 --- a/scripts/process-archive.sh +++ b/scripts/process-archive.sh @@ -188,9 +188,21 @@ makepreview(){ # calculate the factor... FACTOR=$(echo "scale = 4; if($H > $W) s = $H else s = $W ; s / $SIZE" | bc -l) - echo "($FACTOR): ${OUT}:${COMPRESSION}" + # NOTE: bash does not do float comparisons so we cheat again ;) + TOO_SMALL=$(echo "if($FACTOR <= 1) s = 1 else s = 0 ; s" | bc -l) - vips im_shrink "./$IN" "./${OUT}:${COMPRESSION}" $FACTOR $FACTOR 2> /dev/null + # the input is smaller than target size, copy as-is... + if [[ $TOO_SMALL == 1 ]] ; then + echo "$IN: Too small, copying as-is..." + + cp "./$IN" "./$OUT" + + # shrink... + else + echo "($FACTOR): ${OUT}:${COMPRESSION}" + + vips im_shrink "./$IN" "./${OUT}:${COMPRESSION}" $FACTOR $FACTOR 2> /dev/null + fi touch -c -r "./$IN" "./${OUT}"