Created
April 16, 2016 15:08
-
-
Save evejweinberg/ecaa3768a518aa748a1bed7b7f7614ad to your computer and use it in GitHub Desktop.
image tracer to svg to bezier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = '../images/Faces_0.png' | |
ImageTracer.loadImage( | |
path, function(canvas) { | |
// Getting ImageData from canvas with the helper function getImgdata(). | |
var imgd = ImageTracer.getImgdata(canvas); | |
// Synchronous tracing to SVG string | |
var svgstr = ImageTracer.imagedataToSVG(imgd, { pathomit: 152, lcpr: 0, scale: 1, numberofcolors: 12, blurradius: 10 }); | |
// Appending SVG | |
ImageTracer.appendSVGString(svgstr, 'svgcontainer'); | |
// svgstr.length is 263794 | |
console.log(svgstr) | |
var commands = svgstr.split(/(?=[LMCQ])/); | |
console.log(commands) | |
var pointArrays = commands.map(function(d) { | |
var pointsArray = d.slice(1, d.length).split(','); | |
var pairsArray = []; | |
for (var i = 0; i < pointsArray.length; i += 2) { | |
pairsArray.push([+pointsArray[i], +pointsArray[i + 1]]); | |
} | |
return pairsArray; | |
}); | |
console.log(pointArrays) | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment