4 # forked from http://code.sotun.de/git/anondcim/
6 # copyright 2012-2014 Jan Huwald, Felix Kästner (fpunktk)
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
31 # random number between 0 and $1 - 1
32 # read from urandom, sh interpretes numbers with leading 0 wrong, so prepend $1 which doesn't change the result
33 echo $(( $1$(tr -dc "0-9" < /dev/urandom | head -c $((${#1} + 2))) % $1 ))
36 [ $# -gt 0 ] || die "Usage: $0 [-p image_prefix] [-s destination_size (absolute or percentage)] [-d destination_directory] imagefile(s)"
38 type convert >/dev/null 2>&1 || die "ImageMagick (convert, identify) is not installed"
39 type jhead 1>/dev/null 2>&1 || type exiftool 1>/dev/null 2>&1 || die "jhead or exiftool has to be installed"
46 while getopts ':p:s:d:' OPTION
50 file_prefix="${OPTARG}_"
56 # enforce a trailing "/"
57 [ -d "${OPTARG%/}/" ] && dst_dir="${OPTARG%/}/" || die "destination directory \"${OPTARG%/}/\" does not exist"
60 err "not recognised: OPTION=$OPTION, OPTARG=$OPTARG"
64 shift $(($OPTIND - 1))
71 if [ "$dst_dir" = "--same--" ]
73 # if the filename contains a "/" then use this dir
74 [ "$fn" != "${fn%/*}" ] && dst="${fn%/*}/" || dst=""
78 # always use a padded number as destination filename suffix
79 dst="$dst$file_prefix$(echo -n "0000000000$cur" | tail -c ${#total}).jpg"
80 echo "anonymizing \"$fn\" to \"$dst\" ($cur/$total)"
81 [ -f "$fn" ] || { err "source \"$fn\" does not exist and is skipped"; continue; }
82 [ -e "$dst" ] && { err "destination \"$dst\" for source \"$fn\" already exists, anonymization is skipped"; continue; }
85 $(identify -format '%w %h' "$fn")
89 if [ $w -ge 100 ] && [ $h -ge 100 ]
91 if [ $w -ge 1000 ]; then dw=$(($w / 100)); else dw=10; fi
92 if [ $h -ge 1000 ]; then dh=$(($h / 100)); else dh=10; fi
99 -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" \
100 -filter gaussian -define filter:support=5 -define filter:sigma=0.5 \
101 -attenuate 2 +noise Uniform \
102 -resize "$dst_size" \
106 err "image is too small to be distorted and will just be filtered and resized"
109 -filter gaussian -define filter:support=5 -define filter:sigma=0.5 \
110 -attenuate 2 +noise Uniform \
111 -resize "$dst_size" \
117 if [ -x "$(which jhead)" ]
119 jhead -purejpg -q "$dst" || err "removing meta-data with jhead failed"
121 if [ -x "$(which exiftool)" ]
123 exiftool -overwrite_original -all= "$dst" || err "removing meta-data with exiftool failed"