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 23SRC_FILE="assets.svg" 24ASSETS_DIR="assets" 25 26i="$1" 27 28echo "Rendering '$ASSETS_DIR/$i.png'" 29 30if [[ -n "${RENDER_SVG}" ]]; then 31"$RENDER_SVG" --export-id "$i" \ 32"$SRC_FILE" "$ASSETS_DIR/$i.png" 33else 34"$INKSCAPE" --export-id="$i" \ 35--export-id-only \ 36"$EXPORT_FILE_OPTION=$ASSETS_DIR/$i.png" "$SRC_FILE" >/dev/null 37fi 38 39if [[ -n "${OPTIPNG}" ]]; then 40"$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i.png" 41fi 42 43echo "Rendering '$ASSETS_DIR/$i@2.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 192 \ 49--zoom 2 \ 50"$SRC_FILE" "$ASSETS_DIR/$i@2.png" 51else 52"$INKSCAPE" --export-id="$i" \ 53--export-id-only \ 54--export-dpi=192 \ 55"$EXPORT_FILE_OPTION=$ASSETS_DIR/$i@2.png" "$SRC_FILE" >/dev/null 56fi 57 58if [[ -n "${OPTIPNG}" ]]; then 59"$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i@2.png" 60fi 61