From 9d25fadd78cc326a29331b2e228d36615d82e61b Mon Sep 17 00:00:00 2001 From: chiq2045 Date: Thu, 14 May 2020 13:03:26 -0700 Subject: [PATCH 1/6] update potrace to handle svg --- lib/Potrace.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Potrace.js b/lib/Potrace.js index 47cf3d6..d0422bb 100644 --- a/lib/Potrace.js +++ b/lib/Potrace.js @@ -1075,10 +1075,15 @@ Potrace.prototype = { /** * Generates just tag without rest of the SVG file * - * @param {String} [fillColor] - overrides color from parameters + * @param {string} [fillColor=auto] - overrides color from parameters + * @param {Object} [scale={ x: 1, y: 1 }] - override svg scale + * @param {number} [scale.x=1] - scale of the x dimension + * @param {number} [scale.y=1] - scale of the y dimension + * @param {String} [stroke=none] - override svg stroke value + * @param {boolean} [json=false] - return result as a json array of paths * @returns {String} */ - getPathTag: function(fillColor, scale) { + getPathTag: function(fillColor='auto', scale={ x: 1, y: 1 }, stroke='black', json=false) { fillColor = arguments.length === 0 ? this._params.color : fillColor; if (fillColor === Potrace.COLOR_AUTO) { @@ -1095,6 +1100,24 @@ Potrace.prototype = { this._processed = true; } + if (json) { + const tagsArray = []; + tagsArray.push({ + width: this._params.width || this._luminanceData.width, + height: this._params.height || this._luminanceData.height + }); + this._pathlist.forEach(path => { + tagsArray.push({ + d: path, + fill: fillColor, + stroke: stroke, + fillRule: 'evenodd' + }); + }); + + return tagsArray; + } + var tag = ' Date: Thu, 14 May 2020 18:19:35 -0700 Subject: [PATCH 3/6] update to actually render path string --- lib/Potrace.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Potrace.js b/lib/Potrace.js index d0422bb..3a71ad7 100644 --- a/lib/Potrace.js +++ b/lib/Potrace.js @@ -1108,7 +1108,7 @@ Potrace.prototype = { }); this._pathlist.forEach(path => { tagsArray.push({ - d: path, + d: utils.renderCurve(path.curve, scale), fill: fillColor, stroke: stroke, fillRule: 'evenodd' @@ -1190,4 +1190,4 @@ module.exports = Potrace; * Jimp module * @external Jimp * @see https://www.npmjs.com/package/jimp - */ \ No newline at end of file + */ From 8db8de1ae4fe3f295ee2b6ca7a79292d0ec0f85b Mon Sep 17 00:00:00 2001 From: Charles Oroko Date: Tue, 19 May 2020 16:44:33 -0700 Subject: [PATCH 4/6] Add ids to paths --- lib/Potrace.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Potrace.js b/lib/Potrace.js index 3a71ad7..4ca8158 100644 --- a/lib/Potrace.js +++ b/lib/Potrace.js @@ -1114,7 +1114,10 @@ Potrace.prototype = { fillRule: 'evenodd' }); }); - + tagsArray.forEach((path, index) => { + path.id = index; + }); + return tagsArray; } From f9bb144e0678ac439c688473d8a71136b25fdc89 Mon Sep 17 00:00:00 2001 From: Chiq2045 Date: Fri, 7 Aug 2020 18:20:19 -0700 Subject: [PATCH 5/6] create new function to get a JSON object of svg file --- README.md | 3 +- lib/Potrace.js | 78 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index b93f660..624e0ac 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ trace.loadImage('path/to/image.png', function(err) { trace.getSVG(); // returns SVG document contents trace.getPathTag(); // will return just tag + trace.getJson(); // returns SVG document contents in JSON format trace.getSymbol('traced-image'); // will return tag with given ID }); @@ -181,4 +182,4 @@ The GNU General Public License version 2 (GPLv2). Please see [License File](LICE [multilevel-thresholding]: http://www.iis.sinica.edu.tw/page/jise/2001/200109_01.pdf [potrace-by-kilobtye]: https://github.com/kilobtye/potrace [potrace-js-demo]: http://kilobtye.github.io/potrace/ -[jimp]: https://github.com/oliver-moran/jimp \ No newline at end of file +[jimp]: https://github.com/oliver-moran/jimp diff --git a/lib/Potrace.js b/lib/Potrace.js index 4ca8158..920523e 100644 --- a/lib/Potrace.js +++ b/lib/Potrace.js @@ -1075,15 +1075,10 @@ Potrace.prototype = { /** * Generates just tag without rest of the SVG file * - * @param {string} [fillColor=auto] - overrides color from parameters - * @param {Object} [scale={ x: 1, y: 1 }] - override svg scale - * @param {number} [scale.x=1] - scale of the x dimension - * @param {number} [scale.y=1] - scale of the y dimension - * @param {String} [stroke=none] - override svg stroke value - * @param {boolean} [json=false] - return result as a json array of paths + * @param {String} [fillColor] - overrides color from parameters * @returns {String} */ - getPathTag: function(fillColor='auto', scale={ x: 1, y: 1 }, stroke='black', json=false) { + getPathTag: function(fillColor, scale) { fillColor = arguments.length === 0 ? this._params.color : fillColor; if (fillColor === Potrace.COLOR_AUTO) { @@ -1100,27 +1095,6 @@ Potrace.prototype = { this._processed = true; } - if (json) { - const tagsArray = []; - tagsArray.push({ - width: this._params.width || this._luminanceData.width, - height: this._params.height || this._luminanceData.height - }); - this._pathlist.forEach(path => { - tagsArray.push({ - d: utils.renderCurve(path.curve, scale), - fill: fillColor, - stroke: stroke, - fillRule: 'evenodd' - }); - }); - tagsArray.forEach((path, index) => { - path.id = index; - }); - - return tagsArray; - } - var tag = '