Commit 8a31ac8a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

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@kde.org
parent a9dd3b47
#!/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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment