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 dst_dir="${OPTARG%/}/" # enforce a trailing "/"
57 [ -d "$dst_dir" ] || die "destination directory \"$dst_dir\" does not exist"
60 err "not recognised: OPTION=$OPTION, OPTARG=$OPTARG"
64 shift $(($OPTIND - 1))
72 [ -f "$fn" ] || { err "source \"$fn\" does not exist and is skipped"; continue; }
74 if [ "$dst_dir" = "--same--" ]
76 # if the filename contains a "/" then use this dir
77 [ "$fn" != "${fn%/*}" ] && dst="${fn%/*}/" || dst=""
81 # always use a padded number as destination filename suffix
82 dst_jpg="$dst$file_prefix$(echo -n "0000000000$cur" | tail -c ${#total}).jpg"
83 while [ -e "$dst_jpg" ] && [ $addend -lt 1000 ]
85 dst_jpg="$dst$file_prefix$(echo -n "0000000000$(($cur + $addend))" | tail -c ${#total}).jpg"
86 addend=$((addend + 1))
88 [ -e "$dst_jpg" ] && { err "destination \"$dst_jpg\" for source \"$fn\" already exists, anonymization is skipped"; continue; }
90 echo "anonymizing \"$fn\" to \"$dst_jpg\" ($cur/$total)"
93 $(identify -format '%w %h' "$fn")
97 if [ $w -ge 100 ] && [ $h -ge 100 ]
99 if [ $w -ge 1000 ]; then dw=$(($w / 100)); else dw=10; fi
100 if [ $h -ge 1000 ]; then dh=$(($h / 100)); else dh=10; fi
107 -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" \
108 -filter gaussian -define filter:support=5 -define filter:sigma=0.5 \
109 -attenuate 2 +noise Uniform \
110 -resize "$dst_size" \
114 err "image is too small to be distorted and will just be filtered and resized"
117 -filter gaussian -define filter:support=5 -define filter:sigma=0.5 \
118 -attenuate 2 +noise Uniform \
119 -resize "$dst_size" \
125 if [ -x "$(which jhead)" ]
127 jhead -purejpg -q "$dst" || err "removing meta-data with jhead failed"
129 if [ -x "$(which exiftool)" ]
131 exiftool -overwrite_original -all= "$dst" || err "removing meta-data with exiftool failed"