summaryrefslogtreecommitdiff
path: root/navit/icons/navit_svg2png
diff options
context:
space:
mode:
Diffstat (limited to 'navit/icons/navit_svg2png')
-rwxr-xr-xnavit/icons/navit_svg2png36
1 files changed, 36 insertions, 0 deletions
diff --git a/navit/icons/navit_svg2png b/navit/icons/navit_svg2png
index 675207561..668613a61 100755
--- a/navit/icons/navit_svg2png
+++ b/navit/icons/navit_svg2png
@@ -1,5 +1,14 @@
#!/bin/sh
+exitwithhelp()
+{
+ echo "Usage: navit_svg2png <conversion_tool> <output_png_filename> [<width_px> <height_px>]"
+ echo "The input filename is the same than the output png one with svg or svgz extension"
+ echo "Possible conversion tools: ksvgtopng, ksvgtopng4, rsvg-convert, inkscape and convert"
+ echo "width_px and height_px arguments can be omitted if output png size is specified in the filename, like this: imagename_WIDTH_HEIGHT.png (ex. myPng_100_100.png)"
+ exit
+}
+
svgtopng()
{
case $svgtopng in
@@ -15,6 +24,10 @@ svgtopng()
*convert)
$svgtopng -alpha on -background none $3 -resize $1x$2 $4
;;
+ *)
+ echo "Error: unknown conversion tool"
+ exitwithhelp # unknown conversion tool
+ ;;
esac
}
@@ -26,8 +39,27 @@ svgtopng=$1
png=$2
w=$3
h=$4
+
+# if -h or --help arg is passed, print help and exit
+case "$1" in
+ '-h'|'--help'|'')
+ exitwithhelp
+ ;;
+esac
+
+# args num must be == 2 or == 4
+if [ "$#" -ne 2 ] && [ "$#" -ne 4 ];
+then
+ echo "Error: wrong number of arguments"
+ exitwithhelp
+fi
+
case "$png" in
*_[1-9]*_[1-9]*.png)
+ if [ "$#" -ne 2 ]; then
+ echo "Error: output png size is specified by filename and by arguments, plese use only one"
+ exitwithhelp # png size musn't be specifed, only in filename
+ fi
svg=${png%_*_*.png};
h=${png##*_}
w=${png%_$h}
@@ -35,6 +67,10 @@ case "$png" in
w=${w##*_}
;;
*)
+ if [ "$#" -ne 4 ]; then
+ echo "Error: please, specify output png size"
+ exitwithhelp # filename doesn't specify png size, must be done with args 3 and 4
+ fi
svg=${png%.png}
;;
esac