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

kainz.a kainz.a at gmail.com
Wed Feb 24 17:58:15 UTC 2016


I would say we test the script together at CERN sprint and i will have a
look at it that everything works well

Ok?
Andreas
Am 24.02.2016 18:23 schrieb "Aleix Pol" <aleixpol at kde.org>:

> 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
> _______________________________________________
> Plasma-devel mailing list
> Plasma-devel at kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20160224/9beaf09e/attachment-0001.html>


More information about the Plasma-devel mailing list