render-asset.sh
Bourne-Again shell script, ASCII text executable
1#!/bin/bash 2set -ueo pipefail 3 4RENDER_SVG="$(command -v rendersvg)" || true 5INKSCAPE="$(command -v inkscape)" || true 6OPTIPNG="$(command -v optipng)" || true 7 8if [[ -n "${INKSCAPE}" ]]; then 9if "$INKSCAPE" --help | grep -e "--export-filename" > /dev/null; then 10EXPORT_FILE_OPTION="--export-filename" 11elif "$INKSCAPE" --help | grep -e "--export-file" > /dev/null; then 12EXPORT_FILE_OPTION="--export-file" 13elif "$INKSCAPE" --help | grep -e "--export-png" > /dev/null; then 14EXPORT_FILE_OPTION="--export-png" 15fi 16fi 17 18if [[ "$1" == "dark" ]]; then 19SRC_FILE="assets-dark.svg" 20ASSETS_DIR="assets-dark" 21else 22SRC_FILE="assets.svg" 23ASSETS_DIR="assets" 24fi 25 26i="$2" 27 28# @TODO: remove $ZOOM when it will be fixed/implemented in resvg 29GTK2_HIDPI="$(echo "${GTK2_HIDPI-False}" | tr '[:upper:]' '[:lower:]')" 30if [[ "${GTK2_HIDPI}" == "true" ]]; then 31DPI=192 32ZOOM=2 33else 34DPI=96 35ZOOM=1 36fi 37 38echo "Rendering '$ASSETS_DIR/$i.png'" 39 40if [[ -n "${RENDER_SVG}" ]]; then 41# @TODO: remove --zoom when it will be fixed/implemented in resvg 42"$RENDER_SVG" --export-id "$i" \ 43--dpi ${DPI} \ 44--zoom ${ZOOM} \ 45"$SRC_FILE" "$ASSETS_DIR/$i.png" 46else 47"$INKSCAPE" --export-id="$i" \ 48--export-id-only \ 49--export-dpi=${DPI} \ 50"$EXPORT_FILE_OPTION"="$ASSETS_DIR/$i.png" "$SRC_FILE" >/dev/null 51fi 52 53if [[ -n "${OPTIPNG}" ]]; then 54"$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i.png" 55fi 56