Mercurial > libervia-backend
annotate frontends/src/wix/images/split_card.sh @ 253:f45ffbf211e9
MAILDIR + IMAP plugins: first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 17 Jan 2011 00:15:50 +0100 |
parents | 86d249b6d9b7 |
children |
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 | |
143
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
4 #Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
5 |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
6 #This program is free software: you can redistribute it and/or modify |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
7 #it under the terms of the GNU General Public License as published by |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
8 #the Free Software Foundation, either version 3 of the License, or |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
9 #(at your option) any later version. |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
10 |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
11 #This program is distributed in the hope that it will be useful, |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
14 #GNU General Public License for more details. |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
15 |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
16 #You should have received a copy of the GNU General Public License |
119f45746fde
added GPL header to split_card script
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
17 #along with this program. If not, see <http://www.gnu.org/licenses/>. |
81 | 18 |
19 dest_dir=cards | |
20 | |
21 get_face_name() | |
22 { | |
23 if [ $1 -le 10 ] | |
24 then | |
25 echo $1 | |
26 else | |
27 case $1 in | |
28 11) echo valet;; | |
29 12) echo cavalier;; | |
30 13) echo dame;; | |
31 14) echo roi;; | |
32 esac | |
33 fi | |
34 } | |
35 | |
36 get_card_name() | |
37 { | |
38 if [ $1 -le 21 ] | |
39 then | |
40 echo "atout_$1" | |
41 elif [ $1 -eq 22 ]; then | |
42 echo "atout_excuse" | |
43 elif [ $1 -le 36 ]; then | |
44 echo "pique_$(get_face_name $(($1-22)))" | |
45 elif [ $1 -le 50 ]; then | |
46 echo "coeur_$(get_face_name $(($1-36)))" | |
47 elif [ $1 -le 64 ]; then | |
48 echo "carreau_$(get_face_name $(($1-50)))" | |
49 else | |
50 echo "trefle_$(get_face_name $(($1-64)))" | |
51 fi | |
52 } | |
53 | |
82
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
54 #We check the version of convert |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
60 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
|
61 then |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
62 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
|
63 exit 1 |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
64 fi |
21f83796a293
misc: added convert version check in split_card script
Goffi <goffi@goffi.org>
parents:
81
diff
changeset
|
65 |
142
23023aff91fd
split_card script: minor change in syntax help
Goffi <goffi@goffi.org>
parents:
100
diff
changeset
|
66 SYNTAXE="Split card image\nsyntaxe: $0 image_to_split.ext" |
100
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
67 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
68 if [ $# -ne 1 ] |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
69 then |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
70 echo $SYNTAXE |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
71 exit 1 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
72 fi |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
73 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
74 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
|
75 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
76 if [ $? -ne 0 ] |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
77 then |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
78 echo "target file is not an image" |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
79 exit 1 |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
80 fi |
50f1591c8fc6
split_card script: added syntaxe checking
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
81 |
81 | 82 current=`pwd` |
83 #TODO: check directory presence | |
84 #echo "making directory" | |
85 if test -e $dest_dir | |
86 then | |
87 if test -n "`ls -A $dest_dir`" | |
88 then | |
89 echo "$dest_dir directory exists and is not empty !" | |
90 exit 1 | |
91 fi | |
92 else | |
93 mkdir $dest_dir | |
94 fi | |
154
c701f3031ada
misc: split_card script: fixed bad replace
Goffi <goffi@goffi.org>
parents:
143
diff
changeset
|
95 echo "splitting cards" |
84
7471ffcda33b
misc: split_cards: fix bad replacement
Goffi <goffi@goffi.org>
parents:
82
diff
changeset
|
96 convert Tarotcards.jpg -bordercolor black -crop 14x6@ -fuzz 50% -trim $dest_dir/card_%02d.png 2>/dev/null |
81 | 97 cd $dest_dir |
98 | |
99 #POST PROCESSING | |
100 | |
101 nb_files=`ls -A1 card*png | wc -l` | |
102 num=0 | |
103 idx=0 | |
104 max_w=0 | |
105 max_h=0 | |
106 deleted="" | |
107 for file in card*png | |
108 do | |
109 num=$((num+1)) | |
110 size=`stat -c%s $file` | |
111 width=`identify -format "%w" $file` | |
112 height=`identify -format "%h" $file` | |
113 | |
114 if [ $width -gt $max_w ] | |
115 then | |
116 max_w=$width | |
117 fi | |
118 | |
119 if [ $height -gt $max_h ] | |
120 then | |
121 max_h=$height | |
122 fi | |
123 | |
124 echo -n "post processing file [$file] ($num/$nb_files) | " | |
125 echo -n `echo "scale=2;$num/$nb_files*100" | bc`% | |
126 echo -n "\r" | |
127 | |
128 if test $size -lt 1000 | |
129 then #we delete empty files (areas without card on the initial picture) | |
130 deleted="$deleted$file\n" | |
131 rm -f $file | |
132 else | |
133 idx=$((idx+1)) | |
134 #We use transparency for the round corners | |
135 mogrify -fuzz 80% -fill none -draw "matte 0,0 floodfill" \ | |
136 -draw "matte $((width-1)),0 floodfill"\ | |
137 -draw "matte 0,$((height-1)) floodfill"\ | |
138 -draw "matte $((width-1)),$((height-1)) floodfill"\ | |
139 $file | |
140 #Time to rename the cards | |
141 mv "$file" "$(get_card_name $idx).png" | |
142 | |
143 fi | |
144 done | |
145 echo "\nEmpty files deleted:\n$deleted" | |
146 echo "\nBiggest size: ${max_w}X${max_h}" | |
147 cd "$current" | |
148 echo "DONE :)" |