summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorNullptrderef <nullptrderef@proton.me>2024-01-14 13:10:21 +0100
committerNullptrderef <nullptrderef@proton.me>2024-01-14 13:10:21 +0100
commit25dd9ed80b37d3cebda56f5a8beb8ffc0286b482 (patch)
tree0b5986f66ba6c7e346b670a5dd64897c1931b97c /contrib
parent196b46c595fa108b8b67b460924d850a4f02446f (diff)
downloadtaler-mdb-25dd9ed80b37d3cebda56f5a8beb8ffc0286b482.tar.gz
taler-mdb-25dd9ed80b37d3cebda56f5a8beb8ffc0286b482.tar.bz2
taler-mdb-25dd9ed80b37d3cebda56f5a8beb8ffc0286b482.zip
add opt-in parallelization support, properly filter out inkscape output, rather than just silencing
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/convert-svgs-to-pngs.sh58
1 files changed, 39 insertions, 19 deletions
diff --git a/contrib/convert-svgs-to-pngs.sh b/contrib/convert-svgs-to-pngs.sh
index d17136e..c11df7f 100755
--- a/contrib/convert-svgs-to-pngs.sh
+++ b/contrib/convert-svgs-to-pngs.sh
@@ -16,38 +16,58 @@ set -eu
# 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
+echo "${MULTITHREAD:=0}" &> /dev/null; # Whether to parallelize it or not - can cause issues with inkscape somehow, idk
+echo "${MULTITHREAD_COUNT:=0}" &> /dev/null; # How many instances to run before waiting again, if MULTITHREAD is non-falsey
# 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.
+# Convert a specific image
+convertSvgToPng() {
+ case "$CONVERSION_TOOL" in
+ "im")
+ magick convert -density "$TARGET_RESOLUTION" "$1" -resize "$TARGET_RESOLUTION" "$2";
+ ;;
+ "gm")
+ gm convert -density "$TARGET_RESOLUTION" "$1" -resize "$TARGET_RESOLUTION" "$2";
+ ;;
+ "inkscape")
+ inkscape -w "$width" -h "$height" "$1" -o "$2" 2>&1 | grep -v -E 'data:font/|font-(family|style|weight|display)|unicode-range|end_font_face_cb: font face rule limited support' | sed '/^$/d'
+ ;;
+ *)
+ echo "FATAL: Invalid tool \"$CONVERSION_TOOL\"" 1>&2
+ ;;
+ esac;
+}
+
+# Setup Size Variables
+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;
+
# Loop over every directory with imagesfor dir in err ads;
+ctr=0;
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
png=$(sed 's/svg/png/g' <<< "$svg");
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;
+ if [[ "$MULTITHREAD" != "" ]] && [[ "$MULTITHREAD" != "0" ]] && [[ "$MULTITHREAD" != "no" ]] && [[ "$MULTITHREAD" != "false" ]]; then
+ ctr=$((ctr + 1))
+ convertSvgToPng "$svg" "$png" &
+ if [[ $ctr -gt ${MULTITHREAD_COUNT:=4} ]]; then # Inkscape can crash completely if we run too many instances of it at once
+ ctr=0;
+ wait;
+ fi;
+ else
+ convertSvgToPng "$svg" "$png";
+ fi;
done;
+
+ wait;
done;