Tuesday, December 15, 2015

Script to Reduce SVG Size by Rounding Decimal Points

Here is a small script, which rounds the decimal points for each path in a svg image:

function round(toRound, points) {
    return toRound.replace(/[ ][d][=]["']{1}((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']{1}/g, function(m){
        return m.replace(/[\d]*\.[\d]*/g, function(n){
            return +parseFloat(n).toFixed(points)
        });
    });
}


Try It:

Just copy the xml source of your svg image into the "Source" field, and click the "Round"-Button:

(394 Characters)


(0 Characters, 0% saved)

You will find the code of this example here: jsfiddle.net/aLhm2s2z/