symbol_to_img.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. ############################################################################
  3. #
  4. # MODULE: symbol_to_img.sh
  5. # AUTHOR(S): Anna Petrasova, Hamish Bowman, Vaclav Petras
  6. # PURPOSE: Renders the GRASS GIS symbols from dir to a dir of PNGs
  7. # COPYRIGHT: (C) 2012-2016 by Anna Petrasova
  8. # and the GRASS Development Team
  9. #
  10. # This program is free software under the GNU General
  11. # Public License (>=v2). Read the file COPYING that
  12. # comes with GRASS for details.
  13. #
  14. #############################################################################
  15. # generates images for gui/images/symbols
  16. # requires ps.map, Inkscape, and ImageMagic
  17. DIR="$(basename $PWD)"
  18. PSMAP_FILE=tmp.psmap
  19. PS_FILE=tmp.ps
  20. PNG_OUT=png_out
  21. POINT_VECTOR=tmp_one_point
  22. v.in.ascii input=- format=standard -n output=$POINT_VECTOR <<EOF
  23. P 1 1
  24. 100 100
  25. 1 1
  26. EOF
  27. rm -r "$PNG_OUT"
  28. mkdir "$PNG_OUT"
  29. for SYMBOL in *
  30. do
  31. if [ -f "$SYMBOL" ]
  32. then
  33. echo -e "border none\npoint 50% 50%\n symbol $DIR/$SYMBOL\n end\nend" > "$PSMAP_FILE"
  34. ps.map input="$PSMAP_FILE" output="$PS_FILE"
  35. inkscape -f "$PS_FILE" --export-png="$PNG_OUT/$SYMBOL.png" -D -h=30
  36. rm "$PSMAP_FILE" "$PS_FILE"
  37. # ImageMagic optimizes PNGs, no optipng needed
  38. mogrify -gravity center -background transparent -resize 30x30 -extent 30x30 "$PNG_OUT/$SYMBOL.png"
  39. else
  40. echo "$SYMBOL is not regular file"
  41. fi
  42. done
  43. g.remove type=vector name=$POINT_VECTOR -f