Project

General

Profile

Paste
Download (2.35 KB) Statistics
| Branch: | Revision:

root / to_tiles / gen_tiles.sh~ @ 3a569aa8

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