render-asset.sh
Bourne-Again shell script, ASCII text executable
1#!/usr/bin/env 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 23if [[ "$1" == "dark" ]]; then 24SRC_FILE="assets-dark.svg" 25ASSETS_DIR="assets-dark" 26else 27SRC_FILE="assets.svg" 28ASSETS_DIR="assets" 29fi 30 31i="$2" 32 33# @TODO: remove $ZOOM when it will be fixed/implemented in resvg 34GTK2_HIDPI="$(echo "${GTK2_HIDPI-False}" | tr '[:upper:]' '[:lower:]')" 35if [[ "${GTK2_HIDPI}" == "true" ]]; then 36DPI=192 37ZOOM=2 38else 39DPI=96 40ZOOM=1 41fi 42 43echo "Rendering '$ASSETS_DIR/$i.png'" 44 45if [[ -n "${RENDER_SVG}" ]]; then 46# @TODO: remove --zoom when it will be fixed/implemented in resvg 47"$RENDER_SVG" --export-id "$i" \ 48--dpi ${DPI} \ 49--zoom ${ZOOM} \ 50"$SRC_FILE" "$ASSETS_DIR/$i.png" 51else 52"$INKSCAPE" --export-id="$i" \ 53--export-id-only \ 54--export-dpi=${DPI} \ 55"$EXPORT_FILE_OPTION=$ASSETS_DIR/$i.png" "$SRC_FILE" >/dev/null 56fi 57 58if [[ -n "${OPTIPNG}" ]]; then 59"$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i.png" 60fi 61