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