[breeze-icons] /: Include a script that can optimize svg files

Aleix Pol aleixpol at kde.org
Wed Feb 24 17:23:12 UTC 2016


Git commit 8a31ac8ac1056a9065d50845b71336fff74e317c by Aleix Pol.
Committed on 24/02/2016 at 17:16.
Pushed by apol into branch 'master'.

Include a script that can optimize svg files

Now we need to think about how we want this to be executed.

REVIEW: 126740

CCMAIL: plasma-devel at kde.org

A  +43   -0    optimize-svg.sh

http://commits.kde.org/breeze-icons/8a31ac8ac1056a9065d50845b71336fff74e317c

diff --git a/optimize-svg.sh b/optimize-svg.sh
new file mode 100755
index 0000000..a9d1507
--- /dev/null
+++ b/optimize-svg.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+if ! command -v svgo >/dev/null
+then
+    echo "Please install svgo: npm install svgo"
+    exit 1
+fi
+# regarding convertStyleToAttrs, see: https://github.com/svg/svgo/issues/489
+# regarding convertPathData, see: https://github.com/svg/svgo/issues/490
+ARGS="--pretty --disable=convertStyleToAttrs --disable=convertPathData"
+
+function generatePng {
+    inkscape -z -D $1 --export-png=$2 --export-width=200 --export-background=transparent > /dev/null
+}
+
+# args: pngA pngB final.svg temp.svg
+function evaluateOptimization {
+#     that regex is to just take A from "A (B)"
+    res=`compare -metric MAE $1 $2 /dev/null 2>&1 | sed "s/^\\([0-9]*\\).*/\\1/"` #-fuzz 5
+    if [ "$res" -gt 100 ]; then
+        echo "huuuuge difference of $res in $3"
+    else
+        mv $4 $3
+    fi
+}
+
+find . -name "*.svg" -size 4k -print0 | while IFS= read -r -d '' file
+do
+    echo "doing... $file"
+    generatePng "$file" /tmp/A.png
+    svgo -i "$file" -o "$file".tmp.svg $ARGS
+    generatePng "$file".tmp.svg /tmp/B.png
+    evaluateOptimization /tmp/A.png /tmp/B.png "$file" "$file".tmp.svg
+done
+
+find . -name "*.svgz" -print0 | while IFS= read -r -d '' file
+do
+    echo "z-doing... $file"
+    generatePng "$file" /tmp/A.png
+    gunzip "$file" -S .svgz -c | svgo -i - $ARGS | gzip -c > "$file".tmp.svgz
+    generatePng "$file".tmp.svgz /tmp/B.png
+    evaluateOptimization /tmp/A.png /tmp/B.png "$file" "$file".tmp.svgz
+done


More information about the Plasma-devel mailing list