Christoffer
Christoffer

Reputation: 661

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 + '" />');
});

Upvotes: 6

Views: 5186

Answers (1)

Christoffer
Christoffer

Reputation: 661

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.

Upvotes: 6

Related Questions