rename to anondcim
[anondcim.git] / anondcim
1 #!/bin/sh -e
2
3 function die() { 
4     echo -e "$*" >&2
5     exit 1
6 }
7
8 function r() {
9     echo $(($RANDOM % $1))
10 }
11
12 max=$#
13 cur=1
14
15 [ $max -gt 0 ] || die "Usage:\n[IMG_PREFIX=your_prefix] $0 img1.jpg img2.jpg ..."
16 [ -x "$(which convert)" ] || die "ImageMagick is not installed"
17 [ -x "$(which jhead)" ] || die "jhead is not installed"
18
19 while [ $# -gt 0 ]; do
20     dst="$IMG_PREFIX$(seq -w $cur $max|head -n1).jpg"
21     echo -e "[$((100*cur/max))%]\t$1\t-> $dst"
22
23     [ -f "$1" ] || die "$1 does not exist"
24     (! [ -e "$dst" ]) || die "$dst already exists"
25
26     read W H <<EOF
27         $(identify $1 |cut -f3 -d\ |tr x \ )
28 EOF
29
30     [ $W -ge 100 ] && [ $H -ge 100 ] || die "image is too small"
31     
32     if [ $W -ge 1000 ]; then DW=$((W / 100)); else DW=10; fi
33     if [ $H -ge 1000 ]; then DH=$((H / 100)); else DH=10; fi
34     
35     W=$(($W-1))
36     H=$(($H-1))
37     
38     convert $1 \
39         -colorspace RGB \
40         -distort Perspective "$(
41         (   echo $(r $DW)           $(r $DH)           0  0
42             echo $(($W - $(r $DW))) $(r $DH)           $W 0
43             echo $(r $DW)           $(($H - $(r $DH))) 0  $H
44             echo $(($W - $(r $DW))) $(($H - $(r $DH))) $W $H
45         ) | tr " \n" ", ")" \
46         -filter gaussian -define filter:support=5 -define filter:sigma=0.5 \
47         -attenuate 2 +noise Uniform \
48         -resize 50% \
49         -colorspace sRGB \
50         "$dst"
51
52     jhead -purejpg -q "$dst" || die "removing meta-data failed"
53
54     cur=$(($cur + 1))
55     shift
56 done