]> de.git.xonotic.org Git - xonotic/mediasource.git/blob - gfx/luma/render-svg.sh
More icons and HUD graphics
[xonotic/mediasource.git] / gfx / luma / render-svg.sh
1 #!/bin/sh -e
2 # TASK
3 #   Render SVGFILEs from path/filename.svg to DATADIR/path/filename.tga,
4 #   if they are newer than their target tga file.
5 #
6 # NOTES
7 #   To compensate for filter rendering errors and to reduce rbg noise,
8 #   the svg files are rendered at a large size and then scaled down.
9 #
10 # DEPENDENCIES
11 #   librsvg
12 #   imagemagick
13 #
14 # USAGE
15 #   ./render-svg.sh DATADIR [SVGFILE...]
16 #
17 # EXAMPLES
18 #   Single file: ./render-svg.sh ~/.xonotic/data gfx/menu/luminos/cursor.svg
19 #   All files:   ./render-svg.sh ~/.xonotic/data $(find . -name "*.svg")
20
21
22 # Check for arguments
23 if [ -z "$1" ] || [ "${1##*.}" = "svg" ]; then
24         echo "Usage: $0 DATADIR [SVGFILE...]"
25         exit 1
26 fi
27
28
29 data="$1"; shift
30 maxScale=16
31 maxPixels=100000000
32
33
34 for svg in "$@"; do
35         ext="${svg##*.}"
36         dir="$data/${svg%/*}"
37         tga="$data/${svg%.*}.tga"
38
39         if [ "$ext" = "svg" ] && [ -f "$svg" ] && [ "$svg" -nt "$tga" ]; then
40                 echo "Rendering $tga"
41
42                 w=$(identify -format "%w" "$svg")
43                 h=$(identify -format "%h" "$svg")
44                 scale=$(echo "s=sqrt($maxPixels/$w/$h);if(s>$maxScale)s=$maxScale;s" | bc)
45
46                 mkdir -p "$dir"
47                 rsvg-convert -z "$scale" "$svg" | convert - -scale "$w" "$tga"
48         fi
49 done