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 18SRC_FILE="assets.svg" 19ASSETS_DIR="assets" 20 21i="$1" 22 23echo "Rendering '$ASSETS_DIR/$i.png'" 24 25if [[ -n "${RENDER_SVG}" ]]; then 26"$RENDER_SVG" --export-id "$i" \ 27"$SRC_FILE" "$ASSETS_DIR/$i.png" 28else 29"$INKSCAPE" --export-id="$i" \ 30--export-id-only \ 31"$EXPORT_FILE_OPTION"="$ASSETS_DIR/$i.png" "$SRC_FILE" >/dev/null 32fi 33 34if [[ -n "${OPTIPNG}" ]]; then 35"$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i.png" 36fi 37 38echo "Rendering '$ASSETS_DIR/$i@2.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 192 \ 44--zoom 2 \ 45"$SRC_FILE" "$ASSETS_DIR/$i@2.png" 46else 47"$INKSCAPE" --export-id="$i" \ 48--export-id-only \ 49--export-dpi=192 \ 50"$EXPORT_FILE_OPTION"="$ASSETS_DIR/$i@2.png" "$SRC_FILE" >/dev/null 51fi 52 53if [[ -n "${OPTIPNG}" ]]; then 54"$OPTIPNG" -o7 --quiet "$ASSETS_DIR/$i@2.png" 55fi 56