From: fpunktk Date: Mon, 3 Nov 2014 14:53:47 +0000 (+0100) Subject: rewritten for posix-shell (dash), added improvements X-Git-Url: https://fpunktk.de/gitweb/?p=anondcim.git;a=commitdiff_plain;h=ad0081e62008b38a7e35cb88434cd87f105975f4 rewritten for posix-shell (dash), added improvements --- diff --git a/anondcim b/anondcim index 5684bf1..3ccf772 100755 --- a/anondcim +++ b/anondcim @@ -1,56 +1,113 @@ -#!/bin/sh -e +#!/bin/sh -function die() { - echo -e "$*" >&2 +# anondcim +# forked from http://code.sotun.de/git/anondcim/ + +die() { + echo "$*" >&2 exit 1 } -function r() { - echo $(($RANDOM % $1)) +err() { + echo "$*" >&2 } -max=$# -cur=1 +rand() { + # random number between 0 and $1 - 1 + # read from urandom, sh interpretes numbers with leading 0 wrong, so prepend $1 which doesn't change the result + echo $(( $1$(tr -dc "0-9" < /dev/urandom | head -c $((${#1} + 1))) % $1 )) +} -[ $max -gt 0 ] || die "Usage:\n[IMG_PREFIX=your_prefix] $0 img1.jpg img2.jpg ..." -[ -x "$(which convert)" ] || die "ImageMagick is not installed" -[ -x "$(which jhead)" ] || die "jhead is not installed" +[ $# -gt 0 ] || die "Usage: $0 [-p image_prefix] [-s destination_size (absolute or percentage)] [-d destination_directory] imagefile(s)" -while [ $# -gt 0 ]; do - dst="$IMG_PREFIX$(seq -w $cur $max|head -n1).jpg" - echo -e "[$((100*cur/max))%]\t$1\t-> $dst" +[ ! -x "$(which convert)" ] && die "ImageMagick (convert, identify) is not installed" +[ ! -x "$(which jhead)" ] && [ ! -x "$(which exiftool)" ] && die "jhead or exiftool has to be installed" - [ -f "$1" ] || die "$1 does not exist" - (! [ -e "$dst" ]) || die "$dst already exists" +# set default values +file_prefix="" +dst_size="1280" +dst_dir="--same--" - read W H <