d71bc2d582fa8e394d59dfd62d97c5eb6a203d98
[navit-package] / navit / xpm / navit_svg2png
1 #! /bin/bash
2
3 function svgtopng
4 {
5         case $svgtopng in
6         *ksvgtopng|*ksvgtopng4)
7                 $svgtopng $*
8                 ;;
9         *rsvg-convert)
10                 $svgtopng --width=$1 --height=$2 --output $4 $3
11                 ;;
12         *inkscape)
13                 $svgtopng --without-gui --export-width=$1 --export-height=$2 --export-png=$4 $3
14                 ;;
15         *convert)
16                 $svgtopng $3 -resize $1x$2 $4
17                 ;; 
18         esac
19 }
20
21 ulimit -t 5
22 svgtopng=$1
23 png=$2
24 if [[ "$png" = *_[1-9]*_[1-9]*.png ]]; 
25 then
26         svg=${png%_*_*.png};
27         h=${png##*_}
28         w=${png%_$h}
29         h=${h%.png}
30         w=${w##*_}
31 else
32         svg=${png%.png}
33 fi
34 if [ ! -f $svg.svg -a ! -f $svg.svgz ]
35 then
36         svg="$SRCDIR/$svg"
37 fi
38 if [ -f $png -a ! -f $svg.svg ]
39 then
40         touch $png
41 else
42         if [ -f $svg.svg ]
43         then
44                 if [ -z "$w" ]
45                 then
46                         w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
47                 fi
48                 if [ -z "$h" ]
49                 then
50                         h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
51                 fi
52                 svgtopng $w $h $svg.svg $png
53         elif [ -f $svg.svgz ]
54         then
55                 gzip -dc <$svg.svgz >$svg.svg
56                 if [ -z "$w" ]
57                 then
58                         w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
59                 fi
60                 if [ -z "$h" ]
61                 then
62                         h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
63                 fi
64                 svgtopng $w $h $svg.svg $png
65                 rm -f $svg.svg
66         fi
67 fi
68 exit 0