docs
[pspp] / build-aux / svg2png
1 #! /bin/sh
2
3 # Convert svg file to png with a target width and height
4 # width and height are derived from the directory name
5 # of the target. Width and height must be equal
6
7 # Arg1: Source svg file
8 # Arg2: Filename for copyright notice
9 # Arg3: Target png file
10
11 # Extract the icon width from the target path e.g.
12 # src/ui/gui/icons/48x48/actions/file-save.png
13 # should result in a width of 48
14 stripprefix=${3#src*icons\/}
15 width=${stripprefix%%x*}
16
17 if (gimp --version) >/dev/null 2>&1; then
18     echo "Converting $1 to $3 size $widthx$width with GIMP"
19     comment=`cat $2`
20     # If no width can be extracted from the destination path
21     # then take the natural width by setting width to 0
22     case "$width" in
23         [0-9][0-9] | [0-9][0-9][0-9])  ;;
24         *)                 width="0";;
25     esac
26     gimp -i -d -b "\
27 (let* ((image (car (file-svg-load 1 \"$1\" \"$1\" 90 $width $width 0 ))))
28       (gimp-image-attach-parasite image '(\"gimp-comment\" 0 \"$comment\"))
29       (gimp-file-save 1 image (car (gimp-image-get-active-drawable image))
30                       \"$3\" \"$3\"))
31     (gimp-quit 1)"
32 elif (rsvg-convert --version) >/dev/null 2>&1; then
33     echo "Converting $1 to $3 size $widthx$width with rsvg-convert"
34     case $width in
35         [0-9][0-9] | [0-9][0-9][0-9]) widthoption="--width=$width --height=$width" ;;
36         *) widthoption= ;;
37     esac
38     rsvg-convert $widthoption "$1" > "$3"
39 else
40     echo "$0: can't find gimp or rsvg-convert" >&2
41     exit 1
42 fi