#!/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
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:-