Mercurial > libervia-backend
annotate frontends/wix/images/split_card.sh @ 100:50f1591c8fc6
split_card script: added syntaxe checking
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 18 Jun 2010 17:14:14 +0800 |
parents | 7471ffcda33b |
children | 23023aff91fd |
rev | line source |
---|---|
81 | 1 #!/bin/sh |
2 #This script split an image with cards, used to split cards from the Tarot deck found on Wikimedia Commons | |
3 #This script work with any resolution on the initial image | |
4 | |
5 dest_dir=cards | |
6 | |
7 get_face_name() | |
8 { | |
9 if [ $1 -le 10 ] | |
10 then | |
11 echo $1 | |
12 else | |
13 case $1 in | |
14 11) echo valet;; | |
15 12) echo cavalier;; | |
16 13) echo dame;; | |
17 14) echo roi;; | |
18 esac | |
19 fi | |
20 } | |
21 | |
22 get_card_name() | |
23 { | |
24 if [ $1 -le 21 ] | |
25 then | |
26 echo "atout_$1" | |
27 elif [ $1 -eq 22 ]; then | |
28 echo "atout_excuse" | |
29 elif [ $1 -le 36 ]; then | |
30 echo "pique_$(get_face_name $(($1-22)))" | |
31 elif [ $1 -le 50 ]; then | |
32 echo "coeur_$(get_face_name $(($1-36)))" | |
33 elif [ $1 -le 64 ]; then | |
34 echo "carreau_$(get_face_name $(($1-50)))" | |
35 else | |
36 echo "trefle_$(get_face_name $(($1-64)))" | |
37 fi | |
38 } | |
39 | |
82
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
40 #We check the version of convert |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
41 CONVERT_VER=`convert --version | grep Version | grep -o "[0-9]\.[0-9]\.[0-9]"` |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
42 CONVERT_MAJOR=`echo $CONVERT_VER | cut -d . -f 1` |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
43 CONVERT_MINOR=`echo $CONVERT_VER | cut -d . -f 2` |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
44 CONVERT_REV=`echo $CONVERT_VER | cut -d . -f 3` |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
45 |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
46 if [ $CONVERT_MAJOR -lt 6 -o $CONVERT_MAJOR -eq 6 -a $CONVERT_MINOR -lt 6 ] |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
47 then |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
48 echo "ImageMagick convert must be at least version 6.6.0 (current: $CONVERT_VER)" |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
49 exit 1 |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
50 fi |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
51 |
100
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
52 SYNTAXE="Split card image\nsyntaxe: $0 jpeg_image_to_split.jpg" |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
53 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
54 if [ $# -ne 1 ] |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
55 then |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
56 echo $SYNTAXE |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
57 exit 1 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
58 fi |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
59 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
60 echo `file -b --mime-type $1` | grep image 2>&1 > /dev/null |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
61 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
62 if [ $? -ne 0 ] |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
63 then |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
64 echo "target file is not an image" |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
65 exit 1 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
66 fi |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
67 |
81 | 68 current=`pwd` |
69 #TODO: check directory presence | |
70 #echo "making directory" | |
71 if test -e $dest_dir | |
72 then | |
73 if test -n "`ls -A $dest_dir`" | |
74 then | |
75 echo "$dest_dir directory exists and is not empty !" | |
76 exit 1 | |
77 fi | |
78 else | |
79 mkdir $dest_dir | |
80 fi | |
81 echo "splitting $dest_dir" | |
84
7471ffcda33b
misc: split_cards: fix bad replacement
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
82 convert Tarotcards.jpg -bordercolor black -crop 14x6@ -fuzz 50% -trim $dest_dir/card_%02d.png 2>/dev/null |
81 | 83 cd $dest_dir |
84 | |
85 #POST PROCESSING | |
86 | |
87 nb_files=`ls -A1 card*png | wc -l` | |
88 num=0 | |
89 idx=0 | |
90 max_w=0 | |
91 max_h=0 | |
92 deleted="" | |
93 for file in card*png | |
94 do | |
95 num=$((num+1)) | |
96 size=`stat -c%s $file` | |
97 width=`identify -format "%w" $file` | |
98 height=`identify -format "%h" $file` | |
99 | |
100 if [ $width -gt $max_w ] | |
101 then | |
102 max_w=$width | |
103 fi | |
104 | |
105 if [ $height -gt $max_h ] | |
106 then | |
107 max_h=$height | |
108 fi | |
109 | |
110 echo -n "post processing file [$file] ($num/$nb_files) | " | |
111 echo -n `echo "scale=2;$num/$nb_files*100" | bc`% | |
112 echo -n "\r" | |
113 | |
114 if test $size -lt 1000 | |
115 then #we delete empty files (areas without card on the initial picture) | |
116 deleted="$deleted$file\n" | |
117 rm -f $file | |
118 else | |
119 idx=$((idx+1)) | |
120 #We use transparency for the round corners | |
121 mogrify -fuzz 80% -fill none -draw "matte 0,0 floodfill" \ | |
122 -draw "matte $((width-1)),0 floodfill"\ | |
123 -draw "matte 0,$((height-1)) floodfill"\ | |
124 -draw "matte $((width-1)),$((height-1)) floodfill"\ | |
125 $file | |
126 #Time to rename the cards | |
127 mv "$file" "$(get_card_name $idx).png" | |
128 | |
129 fi | |
130 done | |
131 echo "\nEmpty files deleted:\n$deleted" | |
132 echo "\nBiggest size: ${max_w}X${max_h}" | |
133 cd "$current" | |
134 echo "DONE :)" |