2015-12-20 22:32:25 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
for file in $1*.svg; do
|
2016-02-18 11:12:21 +01:00
|
|
|
|
2015-12-20 22:32:25 +01:00
|
|
|
if [[ $file != 'none'* ]]; then
|
2016-02-18 11:12:21 +01:00
|
|
|
|
2015-12-20 22:32:25 +01:00
|
|
|
png=`echo $file | sed s/.svg/.png/`
|
2016-02-18 11:12:21 +01:00
|
|
|
|
2015-12-20 22:32:25 +01:00
|
|
|
# 1. Clean up SVG file.
|
2016-02-18 11:12:21 +01:00
|
|
|
if type xmllint &>/dev/null; then
|
|
|
|
|
2015-12-20 22:32:25 +01:00
|
|
|
# Should be pre-installed on OS X.
|
|
|
|
xmllint $file -o $file --pretty 1
|
2016-02-18 11:12:21 +01:00
|
|
|
|
2015-12-20 22:32:25 +01:00
|
|
|
fi
|
2016-02-18 11:12:21 +01:00
|
|
|
|
2015-12-20 22:32:25 +01:00
|
|
|
# 2. Convert SVG files to PNG.
|
2016-02-18 11:12:21 +01:00
|
|
|
if [ ! -f "$png" ]; then
|
2015-12-20 22:32:25 +01:00
|
|
|
|
2016-02-18 11:12:21 +01:00
|
|
|
if type rsvg-convert &>/dev/null; then
|
2015-12-20 22:32:25 +01:00
|
|
|
|
2016-02-18 11:12:21 +01:00
|
|
|
# Can be installed with Homebrew. (Installation is slow, but conversion is fast.)
|
|
|
|
# brew install librsvg
|
|
|
|
echo "rsvg-convert: converting $file"
|
|
|
|
rsvg-convert $file -o $png
|
2015-12-20 22:32:25 +01:00
|
|
|
|
2016-02-18 11:12:21 +01:00
|
|
|
elif type svgexport &>/dev/null; then
|
2015-12-20 22:32:25 +01:00
|
|
|
|
2016-02-18 11:12:21 +01:00
|
|
|
# Can be installed with NPM. (Installation is fast, but conversion is slow.)
|
|
|
|
# npm install -g svgexport
|
|
|
|
echo "svgexport: converting $file"
|
|
|
|
svgexport $file $png
|
2015-12-20 22:32:25 +01:00
|
|
|
|
2016-02-18 11:12:21 +01:00
|
|
|
fi
|
2015-12-20 22:32:25 +01:00
|
|
|
|
|
|
|
fi
|
2016-02-18 11:12:21 +01:00
|
|
|
|
|
|
|
fi
|
|
|
|
done
|