gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-mdb] branch master updated: add opt-in parallelization supp


From: gnunet
Subject: [taler-taler-mdb] branch master updated: add opt-in parallelization support, properly filter out inkscape output, rather than just silencing
Date: Sun, 14 Jan 2024 13:10:25 +0100

This is an automated email from the git hooks/post-receive script.

nora pushed a commit to branch master
in repository taler-mdb.

The following commit(s) were added to refs/heads/master by this push:
     new 25dd9ed  add opt-in parallelization support, properly filter out 
inkscape output, rather than just silencing
25dd9ed is described below

commit 25dd9ed80b37d3cebda56f5a8beb8ffc0286b482
Author: Nullptrderef <nullptrderef@proton.me>
AuthorDate: Sun Jan 14 13:10:21 2024 +0100

    add opt-in parallelization support, properly filter out inkscape output, 
rather than just silencing
---
 contrib/convert-svgs-to-pngs.sh | 58 +++++++++++++++++++++++++++--------------
 1 file 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;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]