Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert SVG paths to coordinates

How do I convert SVG paths to xy-coordinates? Until recently I used a webpage, which used the jQuery code below. However, I have no idea how to execute the code on a locally stored SVG file. Any help or recommended tool (for Mac) is appreciated.

$("path").each(function(i){
    var path = this;
    var len = path.getTotalLength();
    var p=path.getPointAtLength(0);
    stp=p.x+","+p.y
    for(var i=1; i<len; i++){
        p=path.getPointAtLength(i);
        stp=stp+" "+p.x+","+p.y;
    }
    $(path).replaceWith('<polygon points="' +  stp + '" />');
});
like image 508
Christoffer Avatar asked Nov 19 '15 15:11

Christoffer


1 Answers

All right. Sometimes it is just about knowing the right search terms. In this case, the path coordinates I was talking about is called Well-known text (WKT)—of course. So, a quick google search gave me this SVG to WKT converter. Perfect for my needs.

like image 167
Christoffer Avatar answered Nov 06 '22 05:11

Christoffer