svg2png.sh
958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
# Convert SVG;s to PNG;s using Inkscape.
#
# Usage:
#
# ./svg2png.sh [svg_path] ...
#
# Depends on Inkscape:
#
# sudo apt-get install inkscape
#
# Back-ports of Inkscape stable to older Ubuntu versions:
#
# https://launchpad.net/~inkscape.dev/+archive/stable
#
# Note: For "older" versions of Ubuntu it appears that some dependency for
# Inkscape causes it to render SVG;s poorly (text/offset mismatches)
#
# Author: Pontus Stenetorp <pontus stenetorp se>
# Version: 2011-11-16
INKSCAPE_BIN=inkscape
`hash ${INKSCAPE_BIN} 2>&-`
if [ "$?" -ne "0" ]
then
echo "ERROR: unable to locate inkscape binary (tried '${INKSCAPE_BIN}')" \
1>&2
exit 1
fi
for SVG_PATH in $*
do
PNG_PATH=`echo ${SVG_PATH} | sed -e 's|\.svg$|.png|g'`
# Re-calculate the boundaries for the SVG, it won't be perfect but better
${INKSCAPE_BIN} --export-area-drawing --without-gui \
--file=${SVG_PATH} --export-png=${PNG_PATH}
done