summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaggety <inigohuguet@hotmail.com>2017-11-13 11:27:20 +0100
committerjkoan <jkoan@users.noreply.github.com>2017-11-13 11:27:20 +0100
commit3f26accd04c0f9733f2c8bf7bf58235e2d47a734 (patch)
treee1c01b723ac84a67359a6c6a905638f020cb69eb
parentb004c7216c7c41a270cb08476538e96537a2b7da (diff)
downloadnavit-3f26accd04c0f9733f2c8bf7bf58235e2d47a734.tar.gz
Add:doc:added errors and usage messages to navit_svg2png script (#369)
To know how to use the script you had to inspect the script code. Error messages and help/usage messages added.
-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