oslllo-potrace 4.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +115 -81
  2. package/package.json +13 -7
  3. package/CHANGELOG.md +0 -210
package/README.md CHANGED
@@ -1,127 +1,161 @@
1
1
  # Potrace
2
2
 
3
- [![CI/Test](https://github.com/oslllo/potrace/workflows/CI/Test/badge.svg)](https://github.com/oslllo/potrace/actions)
4
- [![npm](https://img.shields.io/npm/v/oslllo-potrace)](https://www.npmjs.com/package/oslllo-potrace)
3
+ Trace raster images into SVG outlines with a JavaScript port of Potrace JS for Node.js.
5
4
 
6
- A "1:1 output" JavaScript port of [Potrace JS](https://github.com/kilobtye/potrace) for NodeJS.
5
+ [![CI/Test](https://github.com/oslllo/potrace/actions/workflows/ci.test.yml/badge.svg)](https://github.com/oslllo/potrace/actions/workflows/ci.test.yml)
6
+ [![npm](https://img.shields.io/npm/v/oslllo-potrace)](https://www.npmjs.com/package/oslllo-potrace)
7
7
 
8
- ---
8
+ | Original image | Traced output |
9
+ | --- | --- |
10
+ | ![Original tree](example/tree.jpg) | ![Traced tree](example/tree.png) |
9
11
 
10
- | **Original image** | **Potrace output** |
11
- |---------------------------|------------------------------|
12
- | ![Original Image](example/tree.jpg) | ![Potrace Output](example/tree.png) |
12
+ The project aims to match the output of the original Potrace JS port. It reads an image with Jimp, converts its pixels to a binary bitmap, finds outlines, and generates SVG path data.
13
13
 
14
- ---
14
+ ## Contents
15
15
 
16
- [Online Demo](http://kilobtye.github.io/potrace/)
16
+ - [Installation](#installation)
17
+ - [Quick start](#quick-start)
18
+ - [Input and output](#input-and-output)
19
+ - [Tracing options](#tracing-options)
20
+ - [Rendering a preview](#rendering-a-preview)
21
+ - [Development](#development)
22
+ - [Changelog and license](#changelog-and-license)
17
23
 
18
- ---
24
+ ## Installation
19
25
 
20
- ## Why did I create this package ❓
26
+ **Requires Node.js 22.12 or later.** The package uses Jimp 1.7 with patched image detection and validation dependencies. CI tests Node.js 22 and 24 on Linux, macOS, and Windows.
21
27
 
22
- [The issue](https://github.com/tooolbox/node-potrace/issues/7)
28
+ ```sh
29
+ npm install oslllo-potrace
30
+ # Or:
31
+ yarn add oslllo-potrace
32
+ ```
23
33
 
24
- ---
34
+ This README describes the current source on `master`. Check the release's requirements when using an older package version.
25
35
 
26
- # Prerequisites
36
+ ## Quick start
27
37
 
28
- - Node.js v10+
38
+ ```js
39
+ const fs = require("node:fs/promises");
40
+ const Potrace = require("oslllo-potrace");
29
41
 
30
- ## Installation
42
+ async function main() {
43
+ const svg = await Potrace("image.png").trace();
44
+ await fs.writeFile("traced.svg", svg);
45
+ console.log("Saved traced.svg");
46
+ }
31
47
 
32
- ```shell
33
- npm install oslllo-potrace
48
+ main().catch(console.error);
34
49
  ```
35
50
 
36
- ## Basic Usage
51
+ The following examples use the same `Potrace` import. Examples containing `await` belong inside an async function.
52
+
53
+ ## Input and output
37
54
 
38
- ---
55
+ `Potrace(image, options?)` creates an instance, with or without `new`.
39
56
 
40
- Taken from [Example.js](https://github.com/oslllo/potrace/tree/master/example)
57
+ | Parameter | Meaning |
58
+ | --- | --- |
59
+ | `image` | Image file path as a string, or a Buffer containing encoded image bytes |
60
+ | `options` | Optional tracing settings described below |
41
61
 
42
- ---
62
+ Input formats are those decoded by the installed Jimp version, including PNG, JPEG, BMP, TIFF, and GIF. Pass encoded image data, rather than raw RGBA pixels or SVG markup.
43
63
 
44
- ### Example 1
64
+ `.trace()` returns a Promise resolving to an SVG string. It does not write files or accept a callback. Invalid input and decoding errors reject the Promise.
45
65
 
46
66
  ```js
47
- const path = require("path");
48
- const Potrace = require("..");
49
- const fs = require("fs-extra");
50
- const Svg2 = require("oslllo-svg2");
67
+ const image = await require("node:fs/promises").readFile("image.png");
68
+ const svg = await Potrace(image).trace();
69
+ ```
51
70
 
52
- async function example1() {
53
- var source = path.resolve("example/tree.jpg");
54
- var destination = path.resolve("example/tree.svg");
55
- var traced = await Potrace(source).trace();
56
- fs.writeFileSync(destination, traced);
57
- await Svg2(traced).png().extend(10).toFile("example/tree.png");
58
- }
71
+ Create a new instance for each trace. Tracing stores the decoded image and accumulated paths on the instance.
59
72
 
60
- example1().then(() => {
61
- console.log("done");
62
- }).catch((err) => {
63
- throw err;
64
- });
65
- ```
73
+ The default SVG contains one black filled path, which may contain multiple subpaths, with `stroke="none"` and `fill-rule="evenodd"`. Width and height are based on the input bitmap and `svgSize`.
66
74
 
67
- ---
75
+ Tracing is monochrome: pixels with weighted RGB luminance below `128` become foreground; other pixels become background. The threshold is fixed, and alpha is not used in this calculation. Composite transparent artwork onto a suitable background before tracing if needed. Original colors and image metadata are not preserved.
68
76
 
69
- ### Example 2
77
+ ## Tracing options
70
78
 
71
79
  ```js
72
- const path = require("path");
73
- const Potrace = require("..");
74
- const fs = require("fs-extra");
75
- const Svg2 = require("oslllo-svg2");
80
+ const svg = await Potrace("image.png", {
81
+ turnpolicy: Potrace.TURNPOLICY_MINORITY,
82
+ turdsize: 2,
83
+ optcurve: true,
84
+ alphamax: 1,
85
+ opttolerance: 0.2,
86
+ svgSize: 1,
87
+ }).trace();
88
+ ```
76
89
 
77
- async function example2() {
78
- var source = path.resolve("example/tree.jpg");
79
- var destination = path.resolve("example/tree.svg");
80
- var instance = Potrace(source);
81
- var traced = await instance.trace();
82
- fs.writeFileSync(destination, traced);
83
- await Svg2(traced).png().extend(10).toFile("example/tree.png");
84
- }
90
+ | Option | Default | Meaning |
91
+ | --- | --- | --- |
92
+ | `turnpolicy` | `Potrace.TURNPOLICY_MINORITY` | Resolve ambiguities when decomposing bitmap outlines |
93
+ | `turdsize` | `2` | Suppress small speckles by area in bitmap pixels |
94
+ | `optcurve` | `true` | Enable curve optimization |
95
+ | `alphamax` | `1` | Corner threshold controlling the balance between corners and curves |
96
+ | `opttolerance` | `0.2` | Curve optimization tolerance |
97
+ | `svgSize` | `1` | Scale output dimensions and path coordinates by this factor |
98
+ | `opt_type` | `undefined` | Default filled output; set to `"curve"` for black stroked outlines with no fill |
99
+
100
+ Available turn policies:
101
+
102
+ | Constant | Value |
103
+ | --- | --- |
104
+ | `Potrace.TURNPOLICY_BLACK` | `"black"` |
105
+ | `Potrace.TURNPOLICY_WHITE` | `"white"` |
106
+ | `Potrace.TURNPOLICY_LEFT` | `"left"` |
107
+ | `Potrace.TURNPOLICY_RIGHT` | `"right"` |
108
+ | `Potrace.TURNPOLICY_MINORITY` | `"minority"` |
109
+ | `Potrace.TURNPOLICY_MAJORITY` | `"majority"` |
110
+
111
+ Defaults are also exposed as `Potrace.TURDSIZE`, `Potrace.OPTCURVE`, `Potrace.ALPHAMAX`, and `Potrace.OPTTOLERANCE`. Option values are merged with defaults without validation; use values of the documented types.
112
+
113
+ ```js
114
+ // A 100 × 50 bitmap produces a 200 × 100 SVG.
115
+ const larger = await Potrace("image.png", { svgSize: 2 }).trace();
116
+
117
+ // Inspect the traced curves as stroked outlines.
118
+ const outlines = await Potrace("image.png", { opt_type: "curve" }).trace();
119
+ ```
120
+
121
+ `svgSize` scales the traced result; it does not increase source image detail.
85
122
 
86
- example2().then(() => {
87
- console.log("done");
88
- }).catch((err) => {
89
- throw err;
90
- });
123
+ ## Rendering a preview
124
+
125
+ Potrace returns SVG markup. To turn it into a PNG preview, install SVG2 separately:
126
+
127
+ ```sh
128
+ npm install oslllo-svg2
91
129
  ```
92
130
 
93
- ---
131
+ The current SVG2 source requires Node.js 22+. Use a runtime compatible with the SVG2 version you install.
94
132
 
95
- ### Parameters
133
+ ```js
134
+ const Svg2 = require("oslllo-svg2");
96
135
 
97
- - `source` ([**String**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [**Buffer**](https://nodejs.org/api/buffer.html)): path to `image` to trace.
98
- - `options` ([**Object**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)): option parameter object.
99
- - `turnpolicy` ([**string**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)): how to resolve ambiguities in path decomposition. available options are [ `Potrace.TURNPOLICY_BLACK`, `Potrace.TURNPOLICY_WHITE`, `Potrace.TURNPOLICY_LEFT`, `Potrace.TURNPOLICY_RIGHT`, `Potrace.TURNPOLICY_MINORITY`, `Potrace.TURNPOLICY_MAJORITY` ] **(default: Potrace.TURNPOLICY_MINORITY)**.
100
- - `turdsize`: ([**Number**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)) suppress speckles of up to this size **(default: 2)**.
101
- - `optcurve`: ([**Boolean**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)) turn on/off curve optimization **(default: true)**.
102
- - `alphamax`: ([**Number**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)) corner threshold parameter **(default: 1)**.
103
- - `opttolerance`: ([**Number**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)) curve optimization tolerance **(default: 0.2)**.
104
- - `svgSize`: ([**Number**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)) set svg output size. ***NOTE:*** `The resulting image size` <b>=</b> `the original image size` <b>*</b> `size` **(default: 1)**.
105
- - `opt_type`: ([**String**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)) output svg type, available options are [`curve`]
136
+ const svg = await Potrace("image.png").trace();
137
+ await Svg2(svg).png().extend(10).toFile("preview.png");
138
+ ```
139
+
140
+ SVG2 is optional and is not a runtime dependency of Potrace. SVG Fixer uses the two libraries together: SVG2 renders an input SVG to a bitmap, and Potrace traces that bitmap back to a filled SVG path.
106
141
 
107
- ## Changelog
142
+ ## Development
108
143
 
109
- Please see [CHANGELOG](https://github.com/oslllo/potrace/blob/master/CHANGELOG.md) for more information what has changed recently.
144
+ CI runs on pull requests targeting `master`, pushes to `master`, and manual dispatch. Tests cover Node.js 22 and 24 on Linux, macOS, and Windows, plus Node.js 22.12.0 on Linux to verify the minimum supported version.
110
145
 
111
- ## Test
146
+ The dependency overrides select patched `glob` and `minimatch` versions for the test tooling. Keep these overrides until upstream dependencies adopt the patched versions.
112
147
 
113
- ```shell
148
+ ```sh
149
+ npm ci
114
150
  npm test
115
151
  ```
116
152
 
117
- ## Credits
118
-
119
- [Potrace JS Port](https://github.com/kilobtye/potrace) by @kilobtye.
153
+ Tests cover tracing from paths and Buffers, options, invalid input, example images, and exact SVG output comparisons against fixtures. Run the commands from the repository root.
120
154
 
121
- [Original Potrace](http://potrace.sourceforge.net/) by Peter Selinger.
155
+ `npm run example` traces the bundled tree image and renders previews using the development dependency `svg2png-wasm-node-10`. It writes output files under `example/`. The declared `npm run debug` command currently points to a missing `test/debug/debug.js` file and is not usable in this checkout.
122
156
 
123
- [Another Potrace Port For Node.js](https://github.com/tooolbox/node-potrace) maintained by @tooolbox.
157
+ ## Changelog and license
124
158
 
125
- ## License
159
+ See [CHANGELOG.md](CHANGELOG.md) for release history and [LICENSE](LICENSE) for the GPL-2.0 license.
126
160
 
127
- The GNU General Public License v2.0 (GPL-2.0). Please see [License File](https://github.com/oslllo/potrace/blob/master/LICENSE) for more information.
161
+ Based on [Potrace JS](https://github.com/kilobtye/potrace) by kilobtye and the original Potrace algorithm by Peter Selinger. The project was motivated by output differences discussed in [node-potrace issue #7](https://github.com/tooolbox/node-potrace/issues/7).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oslllo-potrace",
3
- "version": "4.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "A \"1:1 output\" JavaScript port of Potrace JS for NodeJS.",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -37,16 +37,22 @@
37
37
  "bugs": {
38
38
  "url": "https://github.com/oslllo/potrace/issues"
39
39
  },
40
- "homepage": "https://github.com/oslllo/potrace#readme",
41
40
  "dependencies": {
42
- "jimp": "^1.6.0"
41
+ "jimp": "^1.7.0"
43
42
  },
44
43
  "devDependencies": {
45
- "chai": "^4.3.6",
46
- "chai-as-promised": "^7.1.1",
47
- "fast-glob": "^3.2.11",
44
+ "chai": "^4.5.0",
45
+ "chai-as-promised": "^7.1.2",
46
+ "fast-glob": "^3.3.3",
48
47
  "fs-extra": "^10.1.0",
49
- "mocha": "^9.2.2",
48
+ "mocha": "^12.0.3",
50
49
  "svg2png-wasm-node-10": "^1.3.1"
50
+ },
51
+ "overrides": {
52
+ "glob": "^14.0.7",
53
+ "minimatch": "^11.0.10"
54
+ },
55
+ "engines": {
56
+ "node": ">=22.12.0"
51
57
  }
52
58
  }
package/CHANGELOG.md DELETED
@@ -1,210 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [4.0.0](https://github.com/oslllo/potrace/compare/v3.0.0...v4.0.0) (2024-10-30)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * severity vulnerability ([7a07a18](https://github.com/oslllo/potrace/commit/7a07a18b54408902fa358227eba00ab7e1346fc8))
14
-
15
- ### Dependencies
16
-
17
- * deps: update jimp to 1.6.0 (#61)
18
-
19
- ## [3.0.0](https://github.com/oslllo/potrace/compare/v2.0.1...v3.0.0) (2024-07-21)
20
-
21
-
22
- ### Bug Fixes
23
-
24
- * fix security vulnerabilities ([cd9eee2](https://github.com/oslllo/potrace/commit/cd9eee2b38bc0aaca0dda4abb422ba5304acdc3d))
25
-
26
- ### [2.0.1](https://www.github.com/oslllo/potrace/compare/v2.0.0...v2.0.1) (2022-07-16)
27
-
28
-
29
- ### Miscellaneous Chores
30
-
31
- * release 2.0.1 ([5eb34e2](https://www.github.com/oslllo/potrace/commit/5eb34e201a74668698ea4b27251afec5fb69e215))
32
-
33
- ## [2.0.0](https://www.github.com/oslllo/potrace/compare/v1.2.0...v2.0.0) (2021-12-31)
34
-
35
-
36
- ### Features
37
-
38
- * **deps:** Simplify dependencies, remove canvas/jsdom ([c013c58](https://www.github.com/oslllo/potrace/commit/c013c58e0fc11c1757fbcf3089e6b42d647fb6af))
39
-
40
-
41
- ### Bug Fixes
42
-
43
- * **deps:** use svg2png-wasm-node-10 for compatibility ([655fe37](https://www.github.com/oslllo/potrace/commit/655fe37a80bc61b62ea0a21c4346dba353154842))
44
- * **example:** add white background ([f3b3980](https://www.github.com/oslllo/potrace/commit/f3b3980298ffed0fcc6a9e4186ac7e6a2cb0627b))
45
-
46
-
47
- ### Miscellaneous Chores
48
-
49
- * release 2.0.0 ([6575466](https://www.github.com/oslllo/potrace/commit/6575466f0f4aeeaedb8302684c0d14903d26f350))
50
-
51
- ## [1.2.0](https://www.github.com/oslllo/potrace/compare/v1.1.4...v1.2.0) (2021-12-30)
52
-
53
-
54
- ### Features
55
-
56
- * **potrace:** new Promise() is not needed with async function ([1adad10](https://www.github.com/oslllo/potrace/commit/1adad10ec6c0b6d19598d47faa36e64a574a756c))
57
-
58
-
59
- ### Bug Fixes
60
-
61
- * **src:** remove unused vars ([a00c02a](https://www.github.com/oslllo/potrace/commit/a00c02a982472ea78dd74fd20c6402e093775002))
62
- * unhandled rejection in Loader.image() ([5edf4a7](https://www.github.com/oslllo/potrace/commit/5edf4a79ed971160578003dd9c236c0ac9accf98))
63
- * unhandled rejection in Loader.image() ([0c3843f](https://www.github.com/oslllo/potrace/commit/0c3843f078a64570043f5a046844197c86a943af))
64
-
65
- ### [1.1.4](https://www.github.com/oslllo/potrace/compare/v1.1.3...v1.1.4) (2021-09-05)
66
-
67
-
68
- ### Bug Fixes
69
-
70
- * vulnerabilities ([e3fc7cb](https://www.github.com/oslllo/potrace/commit/e3fc7cbb39c892e08b39dc90c8ce7b869bf29ce2))
71
-
72
- ### [1.1.3](https://www.github.com/oslllo/potrace/compare/v1.1.2...v1.1.3) (2021-05-06)
73
-
74
-
75
- ### Miscellaneous Chores
76
-
77
- * update dependencies
78
- * release 1.1.3 ([f7784aa](https://www.github.com/oslllo/potrace/commit/f7784aae62f0132377d5f91ee6be38b63d82ddef))
79
-
80
- ## [1.1.2] - 2021/3/31
81
-
82
- ### Security
83
-
84
- - Updated dependences.
85
-
86
- ## [1.1.1] - 2020/12/12
87
-
88
- ### Fixed
89
-
90
- - Fixed vulnerabilities.
91
-
92
- ## [1.1.0] - 2020/9/10
93
-
94
- ### Fixed
95
-
96
- - Added missing package `jimp` needed on runtime.
97
-
98
- ## [1.0.1] - 2020/9/10
99
-
100
- ### Changed
101
-
102
- - Remove tests from npm `package` to help reduce unpacked `package` size.
103
-
104
- ## [1.0.0] - 2020/9/10
105
-
106
- ### Changed
107
-
108
- - Changed `potrace.trace(file, options)` **_=>_** `Potrace(file, options).trace()`.
109
- - Changed `new potrace.Potrace()` **_=>_** `Potrace(file, options)`,
110
- > The `new` declaration for `Potrace` is no more required.
111
- - Refactored codebase.
112
- - Updated tests.
113
- - Moved tests from `jest` to `mocha`.
114
- - Removed unused dependencies.
115
-
116
- ### Fixed
117
-
118
- - Fixed base64 image throwing an error with `jsdom@16.4.0`. See [Travic CI - Build 722428515](https://travis-ci.org/github/oslllo/potrace/builds/722428515)
119
-
120
- ### Security
121
-
122
- - Updated dependences.
123
-
124
- ## [0.0.10] - 2020/7/10
125
-
126
- ### Security
127
-
128
- - Updated dependences.
129
-
130
- ## [0.0.9] - 2020/5/16
131
-
132
- ### Changed
133
-
134
- - Removed unused dependences.
135
-
136
- ### Security
137
-
138
- - Addressed advisory https://www.npmjs.com/advisories/1500.
139
-
140
- ## [0.0.8] - 2020/5/14
141
-
142
- ### Changed
143
-
144
- - Reduced npm package size.
145
-
146
- ## [0.0.7] - 2020/5/12
147
-
148
- ### Fixed
149
-
150
- - Fixed typo in `core.js`.
151
-
152
- ### Added
153
-
154
- - Added badge links to `README.md`.
155
- - Added new tags to `package.json`.
156
-
157
- ### Changed
158
-
159
- - Updated `README.md` content.
160
-
161
- ## [0.0.6] - 2020/5/6
162
-
163
- ### Changed
164
-
165
- - `potrace.Potrace.getSVG()` default size can now be set in parameters.
166
- - Cleaned up tests and code.
167
- - Updated README.md.
168
-
169
- ### Added
170
-
171
- - Added example tests.
172
-
173
- ## [0.0.5] - 2020/4/29
174
-
175
- ### Changed
176
-
177
- - Updated `package.json` description to match repo.
178
-
179
- ## [0.0.4] - 2020/4/29
180
-
181
- ### Fixed
182
-
183
- - Fixed issue with `potrace.trace()` not being able to set parameters.
184
-
185
- ### Changed
186
-
187
- - Refactored tests.
188
- - Updated README.md.
189
-
190
- ### Added
191
-
192
- - Added new tests.
193
-
194
- ## [0.0.3] - 2020/4/29
195
-
196
- ### Changed
197
-
198
- - Updated README.md.
199
-
200
- ## [0.0.2] - 2020/4/28
201
-
202
- ### Changed
203
-
204
- - Updated README.md.
205
-
206
- ## [0.0.1] - 2020/4/28
207
-
208
- ### Added
209
-
210
- - Added everything, initial release.