From: Mart Lubbers Date: Wed, 5 Jun 2019 09:51:41 +0000 (+0200) Subject: allow any format resize.sh X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=e0acd1678c28f5ac13eca2c07d804c6ed5158583;p=dotfiles.git allow any format resize.sh --- diff --git a/shell/.local/bin/resize.sh b/shell/.local/bin/resize.sh index 008ef4e..ae36412 100755 --- a/shell/.local/bin/resize.sh +++ b/shell/.local/bin/resize.sh @@ -1,9 +1,9 @@ #!/bin/bash set -e -if [[ "$#" -ne 2 ]] || ! [[ -e "$1" ]] ||\ +if [[ "$#" -ne 3 ]] || ! [[ -e "$1" ]] ||\ ! [[ "$2" =~ ^[0-9]+[eEpPtTgGmMkKbB]?$ ]]; then - echo "Usage: $0 FILE TGT" >&2 + echo "Usage: $0 INFILE TGT OUTFILE" >&2 echo " TGT is in bytes. Allowed suffixes: bB,kK,mM,gG,tT,pP,eE" >&2 echo " The result will be outputted to stdout. The progress to stderr" >&2 exit @@ -40,9 +40,9 @@ while true; do CUR=$((CUR+D*STEP)) STEP=$((STEP/2)) if [[ $PREV -eq $CUR ]]; then break; fi - if [[ $(convert "$1" -resize ${CUR}x jpg:- | wc -c) -ge $TGT ]]; + convert "$1" -resize ${CUR}x "$3" + if [[ $(wc -c < "$3") -ge $TGT ]]; then D=-1; else D=1; fi echo -n "$CUR," >&2 done echo -e "\b " >&2 -convert "$1" -resize "${CUR}x" jpg:-