render-asset.sh
Bourne-Again shell script, ASCII text executable
1
#!/bin/bash
2
set -ueo pipefail
3
4
RENDER_SVG="$(command -v rendersvg)" || true
5
INKSCAPE="$(command -v inkscape)" || true
6
OPTIPNG="$(command -v optipng)" || true
7
8
if "$INKSCAPE" --help | grep -e "--export-filename" > /dev/null; then
9
EXPORT_FILE_OPTION="--export-filename"
10
elif "$INKSCAPE" --help | grep -e "--export-file" > /dev/null; then
11
EXPORT_FILE_OPTION="--export-file"
12
elif "$INKSCAPE" --help | grep -e "--export-png" > /dev/null; then
13
EXPORT_FILE_OPTION="--export-png"
14
fi
15
16
i="$1"
17
18
echo "Rendering '$i.png'"
19
if [[ -n "${RENDER_SVG}" ]]; then
20
"$RENDER_SVG" --dpi 96 "$i.svg" "$i.png"
21
else
22
"$INKSCAPE" --export-dpi=96 "$EXPORT_FILE_OPTION"="$i.png" "$i.svg" >/dev/null
23
fi
24
25
if [[ -n "${OPTIPNG}" ]]; then
26
"$OPTIPNG" -o7 --quiet "$i.png"
27
fi
28