render-asset.sh
Bourne-Again shell script, ASCII text executable
1
#! /bin/bash
2
set -ueo pipefail
3
4
INKSCAPE="$(which inkscape)"
5
OPTIPNG="$(which optipng)"
6
7
SRC_FILE="assets.svg"
8
ASSETS_DIR="assets"
9
10
i="$1"
11
12
if [[ -f "$ASSETS_DIR/$i.png" ]]; then
13
echo "'$ASSETS_DIR/$i.png' exists."
14
else
15
echo "Rendering '$ASSETS_DIR/$i.png'"
16
"$INKSCAPE" --export-id="$i" \
17
--export-id-only \
18
--export-png="$ASSETS_DIR/$i.png" "$SRC_FILE" >/dev/null \
19
&& "$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i.png"
20
fi
21
22
if [[ -f "$ASSETS_DIR/$i@2.png" ]]; then
23
echo "'$ASSETS_DIR/$i@2.png' exists."
24
else
25
echo "Rendering '$ASSETS_DIR/$i@2.png'"
26
"$INKSCAPE" --export-id="$i" \
27
--export-dpi=192 \
28
--export-id-only \
29
--export-png="$ASSETS_DIR/$i@2.png" "$SRC_FILE" >/dev/null \
30
&& "$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i@2.png"
31
fi
32
33
exit 0
34