{"_id":"@gatsbyjs/potrace","_rev":"3499153","name":"@gatsbyjs/potrace","description":"Potrace in Javascript, for NodeJS","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"daniellewgatsby","email":""},{"name":"gatsby_integrations","email":""},{"name":"kathmbeck","email":""},{"name":"mlgualtieri-gatsby","email":""},{"name":"pieh","email":""},{"name":"seanroberts","email":""},{"name":"serhalp-netlify","email":""}],"time":{"modified":"2024-08-27T20:04:36.000Z","created":"2022-03-29T21:09:45.037Z","3.0.0":"2022-11-25T10:53:02.707Z","2.3.0":"2022-08-19T12:30:24.999Z","2.2.0":"2022-03-29T21:09:45.037Z"},"users":{},"author":{"name":"mattmc"},"repository":{"type":"git","url":"git+https://github.com/tooolbox/node-potrace.git"},"versions":{"3.0.0":{"name":"@gatsbyjs/potrace","version":"3.0.0","description":"Potrace in Javascript, for NodeJS","main":"lib/index.js","scripts":{"test":"cd test && mocha test.js --reporter spec"},"repository":{"type":"git","url":"git+https://github.com/tooolbox/node-potrace.git"},"keywords":["potrace","trace","tracing","svg","bitmap","posterization"],"author":{"name":"mattmc"},"license":"GPL-2.0","bugs":{"url":"https://github.com/tooolbox/node-potrace/issues"},"homepage":"https://github.com/tooolbox/node-potrace#readme","dependencies":{"jimp-compact":"^0.16.1-2"},"devDependencies":{"lodash":"^4.17.21","mocha":"^6.1.4","should":"^13.2.3","should-sinon":"0.0.6","sinon":"^7.3.2"},"gitHead":"eba20c856be007a229689a22c004169fa697577d","_id":"@gatsbyjs/potrace@3.0.0","_nodeVersion":"18.9.0","_npmVersion":"8.19.1","dist":{"shasum":"38e25c90bfc21f770c081b57b50e37d028346362","size":28790,"noattachment":false,"key":"/@gatsbyjs/potrace/-/@gatsbyjs/potrace-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@gatsbyjs/potrace/download/@gatsbyjs/potrace-3.0.0.tgz"},"_npmUser":{"name":"pieh","email":"misiek.piechowiak@gmail.com"},"directories":{},"maintainers":[{"name":"daniellewgatsby","email":""},{"name":"gatsby_integrations","email":""},{"name":"kathmbeck","email":""},{"name":"mlgualtieri-gatsby","email":""},{"name":"pieh","email":""},{"name":"seanroberts","email":""},{"name":"serhalp-netlify","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/potrace_3.0.0_1669373582496_0.416951539669713"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-11-25T11:02:32.222Z","publish_time":1669373582707,"_cnpm_publish_time":1669373582707},"2.3.0":{"name":"@gatsbyjs/potrace","version":"2.3.0","description":"Potrace in Javascript, for NodeJS","main":"lib/index.js","scripts":{"test":"cd test && mocha test.js --reporter spec"},"repository":{"type":"git","url":"git+https://github.com/tooolbox/node-potrace.git"},"keywords":["potrace","trace","tracing","svg","bitmap","posterization"],"author":{"name":"mattmc"},"license":"GPL-3.0","bugs":{"url":"https://github.com/tooolbox/node-potrace/issues"},"homepage":"https://github.com/tooolbox/node-potrace#readme","dependencies":{"jimp-compact":"^0.16.1-2"},"devDependencies":{"lodash":"^4.17.21","mocha":"^6.1.4","should":"^13.2.3","should-sinon":"0.0.6","sinon":"^7.3.2"},"gitHead":"34a92f8d3fadd8f14df030b1c4085830e932ecdf","_id":"@gatsbyjs/potrace@2.3.0","_nodeVersion":"16.15.1","_npmVersion":"8.13.2","dist":{"shasum":"0ac22fb56a02ebc64ce55e4666c4b741cbf27377","size":24561,"noattachment":false,"key":"/@gatsbyjs/potrace/-/@gatsbyjs/potrace-2.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@gatsbyjs/potrace/download/@gatsbyjs/potrace-2.3.0.tgz"},"_npmUser":{"name":"pieh","email":"misiek.piechowiak@gmail.com"},"directories":{},"maintainers":[{"name":"daniellewgatsby","email":""},{"name":"gatsby_integrations","email":""},{"name":"kathmbeck","email":""},{"name":"mlgualtieri-gatsby","email":""},{"name":"pieh","email":""},{"name":"seanroberts","email":""},{"name":"serhalp-netlify","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/potrace_2.3.0_1660912224821_0.7182703791613871"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-08-19T13:49:10.268Z","publish_time":1660912224999,"_cnpm_publish_time":1660912224999},"2.2.0":{"name":"@gatsbyjs/potrace","version":"2.2.0","description":"Potrace in Javascript, for NodeJS","main":"lib/index.js","scripts":{"test":"cd test && mocha test.js --reporter spec"},"repository":{"type":"git","url":"git+https://github.com/tooolbox/node-potrace.git"},"keywords":["potrace","trace","tracing","svg","bitmap","posterization"],"author":{"name":"mattmc"},"license":"GPL-3.0","bugs":{"url":"https://github.com/tooolbox/node-potrace/issues"},"homepage":"https://github.com/tooolbox/node-potrace#readme","dependencies":{"jimp":"^0.16.1"},"devDependencies":{"lodash":"^4.17.21","mocha":"^6.1.4","should":"^13.2.3","should-sinon":"0.0.6","sinon":"^7.3.2"},"gitHead":"d0d3bf40757998187f9adfd90fdda4002032b95a","_id":"@gatsbyjs/potrace@2.2.0","_nodeVersion":"14.17.5","_npmVersion":"6.14.14","dist":{"shasum":"56e88e420c65bb3065caa27772c6acd1c16c4ec4","size":24715,"noattachment":false,"key":"/@gatsbyjs/potrace/-/@gatsbyjs/potrace-2.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@gatsbyjs/potrace/download/@gatsbyjs/potrace-2.2.0.tgz"},"_npmUser":{"name":"wardpeet","email":"ward@coding-tech.com"},"directories":{},"maintainers":[{"name":"daniellewgatsby","email":""},{"name":"gatsby_integrations","email":""},{"name":"kathmbeck","email":""},{"name":"mlgualtieri-gatsby","email":""},{"name":"pieh","email":""},{"name":"seanroberts","email":""},{"name":"serhalp-netlify","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/potrace_2.2.0_1648588184288_0.5637557870309498"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-29T21:09:50.927Z","publish_time":1648588185037,"_cnpm_publish_time":1648588185037}},"readme":"\n\n# node-potrace\nA NodeJS-compatible fork of [Potrace in JavaScript][potrace-by-kilobtye] with some additions, which is in turn a port of [the original Potrace][potrace] — a tool for tracing bitmaps.\n\n![Node.js CI](https://github.com/tooolbox/node-potrace/workflows/Node.js%20CI/badge.svg)\n\n## Example and demo\n\n| **Original image**        | **Potrace output**           | **Posterized output**                   |\n|---------------------------|------------------------------|-----------------------------------------|\n| ![](test/sources/yao.jpg) | ![](https://cdn.rawgit.com/tooolbox/node-potrace/9ee822d/test/example-output.svg) | ![](https://cdn.rawgit.com/tooolbox/node-potrace/9ee822d/test/example-output-posterized.svg) |\n\n(Example image inherited from [online demo of the browser version][potrace-js-demo])\n\n## Usage\n\nInstall\n\n```sh\nnpm install potrace\n```\n\nBasic usage\n\n```js\nvar potrace = require('potrace'),\n    fs = require('fs');\n\npotrace.trace('./path/to/image.png', function(err, svg) {\n  if (err) throw err;\n  fs.writeFileSync('./output.svg', svg);\n});\n```\n\nYou can also provide a configuration object as a second argument.\n\n```js\nvar params = {\n  background: '#49ffd2',\n  color: 'blue',\n  threshold: 120\n};\n\npotrace.trace('./path/to/image.png', params, function(err, svg) {\n  /*...*/\n});\n```\n\nIf you want to run Potrace algorithm multiple times on the same image with different threshold setting and merge results together in a single file - `posterize` method does exactly that.\n\n```js\npotrace.posterize('./path/to/image.png', { threshold: 180, steps: 4 }, function(err, svg) {\n  /*...*/\n});\n\n// or if you know exactly where you want to break it on different levels\n\npotrace.posterize('./path/to/image.png', { steps: [40, 85, 135, 180] }, function(err, svg) {\n  /*...*/\n});\n```\n\n### Advanced usage and configuration\n\nBoth `trace` and `posterize` methods return instances of `Potrace` and `Posterizer` classes respectively to a callback function as third argument. \n\nYou can also instantiate these classes directly:\n\n```js\nvar potrace = require('potrace');\n\n// Tracing\n\nvar trace = new potrace.Potrace();\n\n// You can also pass configuration object to the constructor\ntrace.setParameters({\n  threshold: 128,\n  color: '#880000'\n});\n\ntrace.loadImage('path/to/image.png', function(err) {\n  if (err) throw err;\n\n  trace.getSVG(); // returns SVG document contents\n  trace.getPathTag(); // will return just <path> tag\n  trace.getSymbol('traced-image'); // will return <symbol> tag with given ID\n});\n\n// Posterization\n\nvar posterizer = new potrace.Posterize();\n\nposterizer.loadImage('path/to/image.png', function(err) {\n  if (err) throw err;\n  \n  posterizer.setParameter({\n    color: '#ccc',\n    background: '#222',\n    steps: 3,\n    threshold: 200,\n    fillStrategy: potrace.Posterize.FILL_MEAN\n  });\n  \n  posterizer.getSVG();\n  // or\n  posterizer.getSymbol('posterized-image');\n});\n```\n\nCallback function provided to `loadImage` methods will be executed in context of the `Potrace`/`Posterizer` instance, so if it doesn't go against your code style - you can just do\n\n```js\nnew potrace.Potrace()\n  .loadImage('path/to/image.bmp', function() {\n    if (err) throw err;\n    this.getSymbol('foo');\n  });\n```\n\n[Jimp module][jimp] is used on the back end, so first argument accepted by `loadImage` method could be anything Jimp can read: a `Buffer`, local path or a url string. Supported formats are: PNG, JPEG or BMP. It also could be a Jimp instance (provided bitmap is not modified)\n\n### Parameters\n\n`Potrace` class expects following parameters:\n\n- **turnPolicy** - how to resolve ambiguities in path decomposition. Possible values are exported as constants: `TURNPOLICY_BLACK`, `TURNPOLICY_WHITE`, `TURNPOLICY_LEFT`, `TURNPOLICY_RIGHT`, `TURNPOLICY_MINORITY`, `TURNPOLICY_MAJORITY`. Refer to [this document][potrace-algorithm] for more information (page 4)  \n  (default: `TURNPOLICY_MINORITY`)\n- **turdSize** - suppress speckles of up to this size   \n  (default: 2)\n- **alphaMax** - corner threshold parameter   \n  (default: 1)\n- **optCurve** - curve optimization   \n  (default: true)\n- **optTolerance** - curve optimization tolerance   \n  (default: 0.2)\n- **threshold** - threshold below which color is considered black.\n  Should be a number in range 0..255 or `THRESHOLD_AUTO` in which case threshold will be selected automatically using [Algorithm For Multilevel Thresholding][multilevel-thresholding]  \n  (default: `THRESHOLD_AUTO`)  \n- **blackOnWhite** - specifies colors by which side from threshold should be turned into vector shape  \n  (default: `true`)  \n- **color** - Fill color. Will be ignored when exporting as \\<symbol\\>. (default: `COLOR_AUTO`, which means black or white, depending on `blackOnWhite` property)\n- **background** - Background color. Will be ignored when exporting as \\<symbol\\>. By default is not present (`COLOR_TRANSPARENT`)\n\n---------------\n\n`Posterizer` class has same methods as `Potrace`, in exception of `.getPathTag()`. \nConfiguration object is extended with following properties:\n\n- **fillStrategy** - determines how fill color for each layer should be selected. Possible values are exported as constants:  \n    - `FILL_DOMINANT` - most frequent color in range (used by default), \n    - `FILL_MEAN` - arithmetic mean (average), \n    - `FILL_MEDIAN` - median color, \n    - `FILL_SPREAD` - ignores color information of the image and just spreads colors equally in range 0..\\<threshold\\> (or \\<threshold\\>..255 if `blackOnWhite` is set to `false`),\n- **rangeDistribution** - how color stops for each layer should be selected. Ignored if `steps` is an array. Possible values are:\n    - `RANGES_AUTO` - Performs automatic thresholding (using [Algorithm For Multilevel Thresholding][multilevel-thresholding]). Preferable method for already posterized sources, but takes long time to calculate 5 or more thresholds (exponential time complexity)  \n      *(used by default)*\n    - `RANGES_EQUAL` - Ignores color information of the image and breaks available color space into equal chunks\n- **steps** - Specifies desired number of layers in resulting image. If a number provided - thresholds for each layer will be automatically calculated according to `rangeDistribution` parameter. If an array provided it expected to be an array with precomputed thresholds for each layer (in range 0..255)  \n  (default: `STEPS_AUTO` which will result in `3` or `4`, depending on `threshold` value)\n- **threshold** - Breaks image into foreground and background (and only foreground being broken into desired number of layers). Basically when provided it becomes a threshold for last (least opaque) layer and then `steps - 1` intermediate thresholds calculated. If **steps** is an array of thresholds and every value from the array is lower (or larger if **blackOnWhite** parameter set to `false`) than threshold - threshold will be added to the array, otherwise just ignored.  \n  (default: `Potrace.THRESHOLD_AUTO`)\n- *all other parameters that Potrace class accepts*\n\n**Notes:**\n\n- When number of `steps` is greater than 10 - an extra layer could be added to ensure presence of darkest/brightest colors if needed to ensure presence of probably-important-at-this-point details like shadows or line art.\n- With big number of layers produced image will be looking brighter overall than original due to math error at the rendering phase because of how layers are composited.\n- With default configuration `steps`, `threshold` and `rangeDistribution` settings all set to auto, resulting in a 4 thresholds/color stops being calculated with Multilevel Thresholding algorithm mentioned above. Calculation of 4 thresholds takes 3-5 seconds on average laptop. You may want to explicitly limit number of `steps` to 3 to moderately improve processing speed.  \n\n## Thanks to\n\n- Peter Selinger for [original Potrace tool and algorithm][potrace]\n- @kilobtye for original [javascript port][potrace-by-kilobtye]\n\n## License\n\nThe GNU General Public License version 2 (GPLv2). Please see [License File](LICENSE) for more information.\n\n[potrace]: http://potrace.sourceforge.net/\n[potrace-algorithm]: http://potrace.sourceforge.net/potrace.pdf\n[multilevel-thresholding]: http://www.iis.sinica.edu.tw/page/jise/2001/200109_01.pdf\n[potrace-by-kilobtye]: https://github.com/kilobtye/potrace\n[potrace-js-demo]: http://kilobtye.github.io/potrace/\n[jimp]: https://github.com/oliver-moran/jimp\n","_attachments":{},"homepage":"https://github.com/tooolbox/node-potrace#readme","bugs":{"url":"https://github.com/tooolbox/node-potrace/issues"},"license":"GPL-2.0"}