From e0acd1678c28f5ac13eca2c07d804c6ed5158583 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 5 Jun 2019 11:51:41 +0200 Subject: [PATCH] allow any format resize.sh --- shell/.local/bin/resize.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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:- -- 2.20.1