Révision 3a569aa8
ID | 3a569aa8665d34c923bbd408dcf6d6e1de8ba7bc |
Parent | f60262e6 |
Enfant | 0f3c4dcc |
il manquait le générateur de tiles
Fichiers
- ajouté
- modifié
- copié
- renommé
- supprimé
Révisions
to_tiles/gen_tiles.sh | ||
---|---|---|
1 |
#!/bin/bash |
|
2 |
|
|
3 |
test_mode=false |
|
4 |
memory_limit=256 |
|
5 |
crop_x=256 |
|
6 |
crop_y=256 |
|
7 |
min_scale=0 |
|
8 |
max_scale=8 |
|
9 |
usage="$0 [-x <x_tile_size>] [-y <y_tile_size>] [-p <prefix_result>] [-t] [-h] [-m <min_zoom>] [-M <max_zoom>] <image_to_convert>\n example: $0 -r test_res" |
|
10 |
|
|
11 |
if ! which tifftopnm pnmscale convert > /dev/null; then |
|
12 |
echo "il faut installer les paquets netpbm et imageMagick pour utiliser ce script !" |
|
13 |
fi |
|
14 |
|
|
15 |
while getopts m:M:x:y:p:ht prs |
|
16 |
do |
|
17 |
case $prs in |
|
18 |
t) test_mode=true;; |
|
19 |
x) crop_x=$OPTARG;; |
|
20 |
y) crop_y=$OPTARG;; |
|
21 |
m) min_scale=$OPTARG;; |
|
22 |
M) max_scale=$OPTARG;; |
|
23 |
p) prefix=$OPTARG;; |
|
24 |
\? | h) echo -e $usage |
|
25 |
exit 2;; |
|
26 |
esac |
|
27 |
done |
|
28 |
shift `expr $OPTIND - 1` |
|
29 |
|
|
30 |
if [ -z "$1" ]; then |
|
31 |
echo -e "usage :\n$usage" |
|
32 |
exit 1 |
|
33 |
elif [ ! -f "$1" ]; then |
|
34 |
echo -e "le paramètre $1 ne correspond pas à un nom de fichier !" |
|
35 |
exit 1 |
|
36 |
fi |
|
37 |
|
|
38 |
fname=$1 |
|
39 |
dir=$(dirname $fname) |
|
40 |
|
|
41 |
if [ -z "$prefix" ]; then |
|
42 |
prefix=$(basename $1|sed 's/\..*$//') |
|
43 |
fi |
|
44 |
|
|
45 |
wfname=$prefix.pnm |
|
46 |
if ! $test_mode; then |
|
47 |
tifftopnm $fname > $wfname |
|
48 |
else |
|
49 |
echo "tifftopnm $fname > $wfname" |
|
50 |
fi |
|
51 |
|
|
52 |
echo "préfixe : "$prefix |
|
53 |
|
|
54 |
for ((z=$min_scale; z <= $max_scale; z++)) |
|
55 |
do |
|
56 |
fprefix=${prefix}_00$z |
|
57 |
printf -v ratio %1.4lf $(echo "1 / (2^$z)" | bc -l) |
|
58 |
echo génération du ratio $ratio |
|
59 |
zwfname=tmp.pnm |
|
60 |
|
|
61 |
if $test_mode; then |
|
62 |
if [ $ratio = 1.0000 ]; then |
|
63 |
zwfname=$wfname |
|
64 |
else |
|
65 |
echo "pnmscale $ratio $wfname > $zwfname" |
|
66 |
fi |
|
67 |
echo convert $zwfname \ |
|
68 |
-limit memory $memory_limit \ |
|
69 |
-crop ${crop_x}x${crop_x} \ |
|
70 |
-set filename:tile "%[fx:page.x/${crop_x}]_%[fx:page.y/${crop_y}]" \ |
|
71 |
+repage +adjoin "${fprefix}_%[filename:tile].jpg" |
|
72 |
else |
|
73 |
if [ $ratio = 1.0000 ]; then |
|
74 |
zwfname=$wfname |
|
75 |
else |
|
76 |
pnmscale $ratio $wfname > $zwfname |
|
77 |
fi |
|
78 |
convert $zwfname \ |
|
79 |
-limit memory $memory_limit \ |
|
80 |
-crop ${crop_x}x${crop_x} \ |
|
81 |
-set filename:tile "%[fx:page.x/${crop_x}]_%[fx:page.y/${crop_y}]" \ |
|
82 |
+repage +adjoin "${fprefix}_%[filename:tile].jpg" |
|
83 |
fi |
|
84 |
done |
|
85 |
|
|
86 |
echo ${fprefix}_* |
|
87 |
|
|
88 |
if ! $test_mode; then |
|
89 |
## les lignes ci dessous sont destinnées à mettre des 0 en debut des numéros de ligne et de colonnes |
|
90 |
## Il y a certainement plus simple mais là c'est du rapide et efficace. |
|
91 |
rename 's/_(\d\d)_(\d+\.jpg)$/_0$1_$2/' ${prefix}_* |
|
92 |
rename 's/_(\d)_(\d+\.jpg)$/_00$1_$2/' ${prefix}_* |
|
93 |
rename 's/_(\d+)_(\d\d)(\.jpg)$/_$1_0$2$3/' ${prefix}_* |
|
94 |
rename 's/_(\d+)_(\d)(\.jpg)$/_$1_00$2$3/' ${prefix}_* |
|
95 |
rm $zwfname $wfname |
|
96 |
else |
|
97 |
echo rm $zwfname $wfname |
|
98 |
fi |
to_tiles/gen_tiles.sh~ | ||
---|---|---|
1 |
#!/bin/bash |
|
2 |
|
|
3 |
test_mode=false |
|
4 |
memory_limit=256 |
|
5 |
crop_x=256 |
|
6 |
crop_y=256 |
|
7 |
min_scale=0 |
|
8 |
max_scale=8 |
|
9 |
usage="$0 [-x <x_tile_size>] [-y <y_tile_size>] [-p <prefix_result>] [-t] [-h] [-m <min_zoom>] [-M <max_zoom>] <image_to_convert>\n example: $0 -r test_res" |
|
10 |
|
|
11 |
while getopts m:M:x:y:p:ht prs |
|
12 |
do |
|
13 |
case $prs in |
|
14 |
t) test_mode=true;; |
|
15 |
x) crop_x=$OPTARG;; |
|
16 |
y) crop_y=$OPTARG;; |
|
17 |
m) min_scale=$OPTARG;; |
|
18 |
M) max_scale=$OPTARG;; |
|
19 |
p) prefix=$OPTARG;; |
|
20 |
\? | h) echo -e $usage |
|
21 |
exit 2;; |
|
22 |
esac |
|
23 |
done |
|
24 |
shift `expr $OPTIND - 1` |
|
25 |
|
|
26 |
if [ -z "$1" ]; then |
|
27 |
echo -e "usage :\n$usage" |
|
28 |
exit 1 |
|
29 |
elif [ ! -f "$1" ]; then |
|
30 |
echo -e "le paramètre $1 ne correspond pas à un nom de fichier !" |
|
31 |
exit 1 |
|
32 |
fi |
|
33 |
|
|
34 |
fname=$1 |
|
35 |
dir=$(dirname $fname) |
|
36 |
|
|
37 |
if [ -z "$prefix" ]; then |
|
38 |
prefix=$(basename $1|sed 's/\..*$//') |
|
39 |
fi |
|
40 |
|
|
41 |
wfname=$prefix.pnm |
|
42 |
if ! $test_mode; then |
|
43 |
tifftopnm $fname > $wfname |
|
44 |
else |
|
45 |
echo "tifftopnm $fname > $wfname" |
|
46 |
fi |
|
47 |
|
|
48 |
echo "préfixe : "$prefix |
|
49 |
|
|
50 |
for ((z=$min_scale; z <= $max_scale; z++)) |
|
51 |
do |
|
52 |
fprefix=${prefix}_00$z |
|
53 |
printf -v ratio %1.4lf $(echo "1 / (2^$z)" | bc -l) |
|
54 |
echo génération du ratio $ratio |
|
55 |
zwfname=tmp.pnm |
|
56 |
|
|
57 |
if $test_mode; then |
|
58 |
if [ $ratio = 1.0000 ]; then |
|
59 |
zwfname=$wfname |
|
60 |
else |
|
61 |
echo "pnmscale $ratio $wfname > $zwfname" |
|
62 |
fi |
|
63 |
echo convert $zwfname \ |
|
64 |
-limit memory $memory_limit \ |
|
65 |
-crop ${crop_x}x${crop_x} \ |
|
66 |
-set filename:tile "%[fx:page.x/${crop_x}]_%[fx:page.y/${crop_y}]" \ |
|
67 |
+repage +adjoin "${fprefix}_%[filename:tile].jpg" |
|
68 |
else |
|
69 |
if [ $ratio = 1.0000 ]; then |
|
70 |
zwfname=$wfname |
|
71 |
else |
|
72 |
pnmscale $ratio $wfname > $zwfname |
|
73 |
fi |
|
74 |
convert $zwfname \ |
|
75 |
-limit memory $memory_limit \ |
|
76 |
-crop ${crop_x}x${crop_x} \ |
|
77 |
-set filename:tile "%[fx:page.x/${crop_x}]_%[fx:page.y/${crop_y}]" \ |
|
78 |
+repage +adjoin "${fprefix}_%[filename:tile].jpg" |
|
79 |
fi |
|
80 |
done |
|
81 |
|
|
82 |
echo ${fprefix}_* |
|
83 |
|
|
84 |
if ! $test_mode; then |
|
85 |
## les lignes ci dessous sont destinnées à mettre des 0 en debut des numéros de ligne et de colonnes |
|
86 |
## Il y a certainement plus simple mais là c'est du rapide et efficace. |
|
87 |
rename 's/_(\d\d)_(\d+\.jpg)$/_0$1_$2/' ${prefix}_* |
|
88 |
rename 's/_(\d)_(\d+\.jpg)$/_00$1_$2/' ${prefix}_* |
|
89 |
rename 's/_(\d+)_(\d\d)(\.jpg)$/_$1_0$2$3/' ${prefix}_* |
|
90 |
rename 's/_(\d+)_(\d)(\.jpg)$/_$1_00$2$3/' ${prefix}_* |
|
91 |
rm $zwfname $wfname |
|
92 |
fi |