4 # forked from http://code.sotun.de/git/anondcim/
16 # random number between 0 and $1 - 1
17 # read from urandom, sh interpretes numbers with leading 0 wrong, so prepend $1 which doesn't change the result
18 echo $(( $1$(tr -dc "0-9" < /dev/urandom | head -c $((${#1} + 1))) % $1 ))
21 [ $# -gt 0 ] || die "Usage: $0 [-p image_prefix] [-s destination_size (absolute or percentage)] [-d destination_directory] imagefile(s)"
23 [ ! -x "$(which convert)" ] && die "ImageMagick (convert, identify) is not installed"
24 [ ! -x "$(which jhead)" ] && [ ! -x "$(which exiftool)" ] && die "jhead or exiftool has to be installed"
31 while getopts ':p:s:d:' OPTION
35 file_prefix="${OPTARG}_"
41 # enforce a trailing "/"
42 [ -d "${OPTARG%/}/" ] && dst_dir="${OPTARG%/}/" || die "destination directory \"${OPTARG%/}/\" does not exist"
45 err "not recognised: OPTION=$OPTION, OPTARG=$OPTARG"
49 shift $(($OPTIND - 1))
56 if [ "$dst_dir" = "--same--" ]
58 # if the filename contains a "/" then use this dir
59 [ "$fn" != "${fn%/*}" ] && dst="${fn%/*}/" || dst=""
63 # always use a padded number as destination filename suffix
64 dst="$dst$file_prefix$(echo -n "0000000000$cur" | tail -c ${#total}).jpg"
65 echo "anonymizing \"$fn\" to \"$dst\" ($cur/$total)"
66 [ -f "$fn" ] || { err "source \"$fn\" does not exist and is skipped"; continue; }
67 [ -e "$dst" ] && { err "destination \"$dst\" for source \"$fn\" already exists, anonymization is skipped"; continue; }
70 $(identify -format '%w %h' "$fn")
74 if [ $w -ge 100 ] && [ $h -ge 100 ]
76 if [ $w -ge 1000 ]; then dw=$(($w / 100)); else dw=10; fi
77 if [ $h -ge 1000 ]; then dh=$(($h / 100)); else dh=10; fi
84 -distort Perspective "$(rand $dw) $(rand $dh) 0 0, $(($w - $(rand $dw))) $(rand $dh) $w 0, $(rand $dw) $(($h - $(rand $dh))) 0 $h, $(($w - $(rand $dw))) $(($h - $(rand $dh))) $w $h" \
85 -filter gaussian -define filter:support=5 -define filter:sigma=0.5 \
86 -attenuate 2 +noise Uniform \
91 err "image is too small to be distorted and will just be filtered and resized"
94 -filter gaussian -define filter:support=5 -define filter:sigma=0.5 \
95 -attenuate 2 +noise Uniform \
102 if [ -x "$(which jhead)" ]
104 jhead -purejpg -q "$dst" || err "removing meta-data with jhead failed"
106 if [ -x "$(which exiftool)" ]
108 exiftool -overwrite_original -all= "$dst" || err "removing meta-data with exiftool failed"