annotate frontends/wix/images/split_card.sh @ 81:104a815bb23f

Tarot game: first draft - wix: first draft of cards window - shell script to split cards from Tarot game found on wikimedia commons
author Goffi <goffi@goffi.org>
date Sun, 18 Apr 2010 15:47:10 +1000
parents
children 21f83796a293
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/bin/sh
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 #This script split an image with cards, used to split cards from the Tarot deck found on Wikimedia Commons
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3 #This script work with any resolution on the initial image
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 dest_dir=cards
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 get_face_name()
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 {
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 if [ $1 -le 10 ]
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 echo $1
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 else
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 case $1 in
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 11) echo valet;;
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 12) echo cavalier;;
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 13) echo dame;;
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 14) echo roi;;
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 esac
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 fi
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 }
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 get_card_name()
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 {
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 if [ $1 -le 21 ]
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 echo "atout_$1"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 elif [ $1 -eq 22 ]; then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 echo "atout_excuse"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 elif [ $1 -le 36 ]; then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 echo "pique_$(get_face_name $(($1-22)))"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 elif [ $1 -le 50 ]; then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 echo "coeur_$(get_face_name $(($1-36)))"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 elif [ $1 -le 64 ]; then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 echo "carreau_$(get_face_name $(($1-50)))"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 else
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 echo "trefle_$(get_face_name $(($1-64)))"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 fi
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 }
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 current=`pwd`
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 #TODO: check directory presence
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 #echo "making directory"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 if test -e $dest_dir
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 if test -n "`ls -A $dest_dir`"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 echo "$dest_dir directory exists and is not empty !"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 exit 1
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 fi
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 else
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 mkdir $dest_dir
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 fi
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 echo "splitting $dest_dir"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 convert Tarot$dest_dir.jpg -bordercolor black -crop 14x6@ -fuzz 50% -trim $dest_dir/card_%02d.png 2>/dev/null
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 cd $dest_dir
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 #POST PROCESSING
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 nb_files=`ls -A1 card*png | wc -l`
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 num=0
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 idx=0
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 max_w=0
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 max_h=0
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 deleted=""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 for file in card*png
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 do
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 num=$((num+1))
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 size=`stat -c%s $file`
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 width=`identify -format "%w" $file`
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 height=`identify -format "%h" $file`
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 if [ $width -gt $max_w ]
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 max_w=$width
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 fi
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 if [ $height -gt $max_h ]
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 then
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 max_h=$height
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 fi
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 echo -n "post processing file [$file] ($num/$nb_files) | "
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 echo -n `echo "scale=2;$num/$nb_files*100" | bc`%
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 echo -n "\r"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 if test $size -lt 1000
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 then #we delete empty files (areas without card on the initial picture)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 deleted="$deleted$file\n"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 rm -f $file
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 else
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 idx=$((idx+1))
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 #We use transparency for the round corners
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 mogrify -fuzz 80% -fill none -draw "matte 0,0 floodfill" \
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 -draw "matte $((width-1)),0 floodfill"\
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 -draw "matte 0,$((height-1)) floodfill"\
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 -draw "matte $((width-1)),$((height-1)) floodfill"\
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 $file
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 #Time to rename the cards
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 mv "$file" "$(get_card_name $idx).png"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 fi
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 done
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 echo "\nEmpty files deleted:\n$deleted"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 echo "\nBiggest size: ${max_w}X${max_h}"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 cd "$current"
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 echo "DONE :)"