"Fossies" - the Fresh Open Source Software Archive

Member "navit-0.5.6/navit/icons/navit_svg2png" (6 Mar 2021, 2704 Bytes) of package /linux/privat/navit-0.5.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "navit_svg2png": 0.5.5_vs_0.5.6.

    1 #!/bin/sh
    2 
    3 exitwithhelp()
    4 {
    5     echo "Usage: navit_svg2png <conversion_tool> <output_png_filename> [<width_px> <height_px>]"
    6     echo "The input filename is the same than the output png one with svg or svgz extension"
    7     echo "Possible conversion tools: ksvgtopng, ksvgtopng4, rsvg-convert, inkscape and convert"
    8     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)"
    9     exit
   10 }
   11 
   12 svgtopng()
   13 {
   14     case $svgtopng in
   15     *ksvgtopng|*ksvgtopng4)
   16         $svgtopng $*
   17         ;;
   18     *rsvg-convert)
   19         $svgtopng --width=$1 --height=$2 --output $4 $3
   20         ;;
   21     *inkscape)
   22         $svgtopng --export-width=$1 --export-height=$2 --export-type=png --export-filename=$4 $3
   23         ;;
   24     *convert)
   25         $svgtopng -alpha on -background none $3 -resize $1x$2 $4
   26         ;;
   27     *)
   28         echo "Error: unknown conversion tool"
   29         exitwithhelp    # unknown conversion tool
   30         ;;
   31     esac
   32 }
   33 
   34 if [ "$OSTYPE" != "cygwin" -a "$OSTYPE" != "msys" ]; then
   35     ulimit -t 10
   36 fi
   37 
   38 svgtopng=$1
   39 png=$2
   40 w=$3
   41 h=$4
   42 
   43 # if -h or --help arg is passed, print help and exit
   44 case "$1" in
   45     '-h'|'--help'|'')
   46         exitwithhelp
   47         ;;
   48 esac
   49 
   50 # args num must be == 2 or == 4
   51 if [ "$#" -ne 2 ] && [ "$#" -ne 4 ];
   52 then
   53     echo "Error: wrong number of arguments"
   54     exitwithhelp
   55 fi
   56 
   57 case "$png" in
   58     *_[1-9]*_[1-9]*.png)
   59         if [ "$#" -ne 2 ]; then
   60             echo "Error: output png size is specified by filename and by arguments, plese use only one"
   61             exitwithhelp    # png size musn't be specifed, only in filename
   62         fi
   63         svg=${png%_*_*.png};
   64         h=${png##*_}
   65         w=${png%_$h}
   66         h=${h%.png}
   67         w=${w##*_}
   68         ;;
   69     *)
   70         if [ "$#" -ne 4 ]; then
   71             echo "Error: please, specify output png size"
   72             exitwithhelp    # filename doesn't specify png size, must be done with args 3 and 4
   73         fi
   74         svg=${png%.png}
   75         ;;
   76 esac
   77 if [ ! -f $svg.svg -a ! -f $svg.svgz ]
   78 then
   79     svg="$SRCDIR/$svg"
   80 fi
   81 if [ -f $png -a ! -f $svg.svg ]; then
   82     # width and height seems to be defined as part of the file name
   83     touch $png
   84 else
   85     # use width and height from the svg image
   86     if [ -f $svg.svg ]
   87     then
   88         if [ -z "$w" ]
   89         then
   90             w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
   91         fi
   92         if [ -z "$h" ]
   93         then
   94             h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
   95         fi
   96         svgtopng $w $h $svg.svg $png
   97     elif [ -f $svg.svgz ]
   98     then
   99         gzip -dc <$svg.svgz >$svg.svg
  100         if [ -z "$w" ]
  101         then
  102             w=$(grep 'width="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*width="//' -e 's/[pxt]*".*//')
  103         fi
  104         if [ -z "$h" ]
  105         then
  106             h=$(grep 'height="[0-9pxt.]*"' $svg.svg | head -n 1 | sed -e 's/.*height="//' -e 's/[pxt]*".*//')
  107         fi
  108         svgtopng $w $h $svg.svg $png
  109         rm -f $svg.svg
  110     fi
  111 fi
  112 exit 0