From 339c338308954ba1398612113536129720eae79b Mon Sep 17 00:00:00 2001 From: Nullptrderef Date: Sun, 14 Jan 2024 00:54:48 +0100 Subject: improve conversion script to support multiple backends --- contrib/convert-svgs-to-pngs | 47 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'contrib') diff --git a/contrib/convert-svgs-to-pngs b/contrib/convert-svgs-to-pngs index a132794..d17136e 100755 --- a/contrib/convert-svgs-to-pngs +++ b/contrib/convert-svgs-to-pngs @@ -1,14 +1,53 @@ #!/bin/bash # This file is in the public domain. # Convert local SVGs to the PNGs for display. + +# Please make sure you have the relevant fonts installed - in the case of the builtin SVGs, these are the following: +# All: +# - Roboto (Arch: `ttf-roboto`) +# ADs: +# - Inter (Arch: `inter-font`) +# - Source Sans Pro (Arch: `adobe-source-sans-fonts`) +# Err: +# - JetBrains Mono (Arch: `ttf-jetbrains-mono`) + set -eu -for dir in err; + +# General Config +echo "${CONVERSION_TOOL:=inkscape}" &> /dev/null; # Which conversion tool to use - "im" (imagemagick), "gm" (graphicsmagick, can produce weird font results) and "inkscape" +echo "${TARGET_RESOLUTION:="768x576"}" &> /dev/null; # The final output resolution + +# Imagemagick/Graphicsmagick Options +echo "${IM_SCALE_RESOLUTION:="1536x1152"}" &> /dev/null; # The resolution we set when telling magick to parse the SVG - higher than TARGET_RESOLUTION due to some blurry imagery caused by imagemagick otherwise. + +# Loop over every directory with imagesfor dir in err ads; +for dir in err ads; do mkdir -p "${dir}/png" + + if [[ "$CONVERSION_TOOL" == "inkscape" ]]; then + width=$(echo -n "$TARGET_RESOLUTION" | sed 's/x/ /' | awk '{print $1}') + height=$(echo -n "$TARGET_RESOLUTION" | sed 's/x/ /' | awk '{print $2}') + fi; + + # Convert them for svg in "${dir}/svg/"*; - do + do png=$(sed 's/svg/png/g' <<< "$svg"); - echo "Converting $svg to $png" - inkscape -w 768 -h 576 "$svg" -o "$png" &> /dev/null + echo "Converting $svg to $png with $CONVERSION_TOOL"; + case "$CONVERSION_TOOL" in + "im") + magick convert -density "$TARGET_RESOLUTION" "$svg" -resize "$TARGET_RESOLUTION" "$png"; + ;; + "gm") + gm convert -density "$TARGET_RESOLUTION" "$svg" -resize "$TARGET_RESOLUTION" "$png"; + ;; + "inkscape") + inkscape -w "$width" -h "$height" "$svg" -o "$png" &> /dev/null + ;; + *) + echo "FATAL: Invalid tool \"$CONVERSION_TOOL\"" 1>&2 + ;; + esac; done; done; -- cgit v1.2.3