vecto-svg 0.2.0__tar.gz

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.
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hugo GB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.5
2
+ Name: vecto-svg
3
+ Version: 0.2.0
4
+ Summary: Turn PNG/JPG images into clean, small SVGs: logos, icons, signatures, cut files, colour art. CLI, Python API and MCP server.
5
+ Project-URL: Homepage, https://github.com/hugoogb/vecto
6
+ Project-URL: Issues, https://github.com/hugoogb/vecto/issues
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: bitmap,cricut,laser,mcp,png-to-svg,potrace,svg,trace,vectorize,vectorizer
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: opencv-python-headless>=4.10
21
+ Requires-Dist: pillow>=11
22
+ Requires-Dist: potracer>=0.0.4
23
+ Requires-Dist: resvg-py>=0.5.0
24
+ Requires-Dist: scour>=0.38.2
25
+ Requires-Dist: typer>=0.15
26
+ Requires-Dist: vtracer>=0.6.15
27
+ Provides-Extra: mcp
28
+ Requires-Dist: mcp>=1.2; extra == 'mcp'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # vecto
32
+
33
+ Turn PNG, JPG and WebP images into clean, small SVGs, and find out how accurate each one is.
34
+
35
+ `vecto` traces logos, icons, signatures, line art, colour illustrations and pixel art. It also makes cut files for Cricut, Silhouette, laser cutters and plotters. You can use it as a **CLI**, a **Python library**, or an **MCP server** that AI assistants call directly.
36
+
37
+ - **Presets instead of knobs.** Pick `logo`, `signature`, `cut`, `pixel` and so on instead of tuning potrace settings.
38
+ - **Every result is scored.** vecto renders the SVG back to pixels and compares it with the source, so you can see how faithful the trace is.
39
+ - **`--auto` tuning.** It searches tracing settings for the *smallest* SVG that still matches the source.
40
+ - **Handles real inputs.** It deals with transparent PNGs, light-on-dark images, tiny low-resolution logos, phone photos of signatures and dusty scans.
41
+ - **No system dependencies.** Every dependency installs from pip wheels on Linux, macOS and Windows. You don't need the `potrace` binary or Cairo.
42
+
43
+ ## Examples
44
+
45
+ | Input | Command | Output (SVG) |
46
+ | --- | --- | --- |
47
+ | <img src="examples/logo.png" width="200"> 200×80 transparent PNG | `vecto convert logo.png -p logo --auto` | <img src="examples/out/logo.svg" width="200"><br>3.0 KB · fidelity 98.3% · edge error 0.24 px |
48
+ | <img src="examples/signature.jpg" width="240"> phone photo, uneven light, dust | `vecto convert signature.jpg -p signature` | <img src="examples/out/signature.svg" width="240"><br>3.3 KB · transparent · keeps the ink colour |
49
+ | <img src="examples/art.png" width="200"> flat illustration | `vecto convert art.png -p color` | <img src="examples/out/art.svg" width="200"><br>2.3 KB · 6 colours · fidelity 99.6% |
50
+ | <img src="examples/pixel.png" width="128" style="image-rendering:pixelated"> 16×16 sprite | `vecto convert pixel.png -p pixel` | <img src="examples/out/pixel.svg" width="128"><br>2.0 KB · pixel-exact |
51
+ | <img src="examples/logo.png" width="200"> | `vecto convert logo.png -p cut --outline` | <img src="examples/out/logo-cut.svg" width="200"><br>cut lines for a laser or plotter |
52
+
53
+ The example inputs are synthetic and generated by [`examples/make_examples.py`](examples/make_examples.py).
54
+
55
+ ## Install
56
+
57
+ vecto needs Python 3.12 or newer.
58
+
59
+ ```bash
60
+ uv tool install git+https://github.com/hugoogb/vecto
61
+ ```
62
+
63
+ You can use pipx instead:
64
+
65
+ ```bash
66
+ pipx install git+https://github.com/hugoogb/vecto
67
+ ```
68
+
69
+ To use the MCP server, install the `mcp` extra:
70
+
71
+ ```bash
72
+ uv tool install "vecto-svg[mcp] @ git+https://github.com/hugoogb/vecto"
73
+ ```
74
+
75
+ The package is called `vecto-svg` because `vecto` is already taken on PyPI. The command is still `vecto`.
76
+
77
+ For development:
78
+
79
+ ```bash
80
+ git clone https://github.com/hugoogb/vecto && cd vecto
81
+ uv sync --all-extras
82
+ uv run pytest
83
+ ```
84
+
85
+ ## Usage
86
+
87
+ ### Convert one image
88
+
89
+ ```bash
90
+ vecto convert input.png # writes input.svg
91
+ vecto convert input.png out.svg -p logo # use a preset
92
+ vecto convert input.png --auto # smallest SVG that still matches
93
+ vecto convert input.png --preview # also writes out.preview.png
94
+ ```
95
+
96
+ Each run prints a summary to stderr:
97
+
98
+ ```
99
+ input.svg: 176.75x64, 3.0 KB, 1 paths, fidelity 98.3%, edge error 0.24px, 18 settings tried
100
+ ```
101
+
102
+ ### Pipes and scripts
103
+
104
+ Use `-` for stdin or stdout. Add `--json` to get machine-readable results.
105
+
106
+ ```bash
107
+ curl -s https://example.com/logo.png | vecto convert - -p logo > logo.svg
108
+ vecto convert logo.png logo.svg --json | jq '.fidelity, .bytes'
109
+ ```
110
+
111
+ ### Convert a folder
112
+
113
+ `batch` accepts every `convert` option. Without `--jobs` it uses one worker per CPU. One broken file doesn't stop the batch: failures are listed at the end, and the exit code is non-zero if any file failed.
114
+
115
+ ```bash
116
+ vecto batch ./images ./svgs -p icon --recursive --jobs 8
117
+ vecto batch ./scans ./out -p signature --skip-existing --json > report.json
118
+ ```
119
+
120
+ ### Presets
121
+
122
+ Run `vecto presets` to list them:
123
+
124
+ | Preset | For |
125
+ | --- | --- |
126
+ | `logo` | Flat logos and wordmarks. Keeps the ink colour, smooth curves, tight crop. |
127
+ | `icon` | Small icons and glyphs. Upscales aggressively before tracing. |
128
+ | `signature` | Scanned or photographed signatures and handwriting. Handles uneven paper, removes dust, transparent background. |
129
+ | `lineart` | Ink drawings, sketches and comics in black and white. |
130
+ | `cut` | Cutting machines (Cricut, Silhouette, laser, plotter). One colour, no specks, simplified paths. Add `--outline` for stroke-only cut lines. |
131
+ | `color` | Colour illustrations, flat artwork and stickers. |
132
+ | `photo` | Photographs, with a posterised look. |
133
+ | `pixel` | Pixel art. Keeps hard square pixels. |
134
+
135
+ Any option you set overrides the preset. For example, `-p cut --turdsize 5` keeps smaller details.
136
+
137
+ ### Fidelity and `--auto`
138
+
139
+ After tracing, vecto renders the SVG and compares it with the source.
140
+
141
+ - **Mono** results get two numbers:
142
+ - **fidelity** is the intersection-over-union of the ink pixels. Unlike plain pixel accuracy, it isn't inflated by empty background. Specks that were removed on purpose (see `--turdsize`) don't count against it.
143
+ - **edge error** is how far the outlines drift from the source, in pixels (99th percentile). Area scores barely notice rounded corners, but edge error does.
144
+ - **Colour** results get one number: 1 minus the mean colour difference.
145
+
146
+ `--auto` tries different curve-fitting settings (`alphamax` and `opttolerance` for mono, `colors` and `layer_difference` for colour). It keeps the **smallest file** that meets `--target` (default 0.95 mono, 0.98 colour) and, for mono, `--max-edge` (default 0.5 px). If no setting qualifies, it returns the most faithful result with a warning. Noise filtering is never auto-tuned. A search that rewards fidelity would always choose to keep the dust.
147
+
148
+ ### Use from Python
149
+
150
+ ```python
151
+ from vecto import vectorize, build_options
152
+
153
+ result = vectorize("logo.png", build_options("logo"), auto=True)
154
+ print(result.fidelity, result.edge_error, result.bytes)
155
+ open("logo.svg", "w").write(result.svg)
156
+
157
+ # numpy arrays (RGB, RGBA or greyscale) and raw bytes work too
158
+ result = vectorize(image_array, build_options("cut", turdsize=10))
159
+ ```
160
+
161
+ ### Use from AI assistants (MCP)
162
+
163
+ `vecto mcp` starts a stdio MCP server with two tools: `vectorize_image` and `list_presets`. The tool returns fidelity, size and warnings, so an agent can check the result instead of guessing.
164
+
165
+ To add it to Claude Code:
166
+
167
+ ```bash
168
+ claude mcp add vecto -- uvx --from "vecto-svg[mcp] @ git+https://github.com/hugoogb/vecto" vecto mcp
169
+ ```
170
+
171
+ For Claude Desktop, Cursor and other MCP clients, add this to the MCP config:
172
+
173
+ ```json
174
+ {
175
+ "mcpServers": {
176
+ "vecto": {
177
+ "command": "uvx",
178
+ "args": ["--from", "vecto-svg[mcp] @ git+https://github.com/hugoogb/vecto", "vecto", "mcp"]
179
+ }
180
+ }
181
+ }
182
+ ```
183
+
184
+ ## Options
185
+
186
+ | Option | Default | Description |
187
+ | --- | --- | --- |
188
+ | `-p, --preset` | none | Start from a preset (see above). |
189
+ | `-m, --mode` | `mono` | `mono` traces one colour with potrace. `color` traces colour layers with vtracer. |
190
+ | `--auto` | off | Search for the smallest SVG that meets `--target` and `--max-edge`. |
191
+ | `--target` | 0.95 / 0.98 | Fidelity goal for `--auto`. |
192
+ | `--max-edge` | 0.5 | [mono] Maximum edge drift for `--auto`, in pixels. |
193
+ | `-t, --threshold` | auto (Otsu) | Cut-off between ink and background (0–255). |
194
+ | `--adaptive` | off | Local thresholding, for shadows and uneven paper. |
195
+ | `--invert / --no-invert` | auto | Swap ink and background. By default, dark backgrounds are detected automatically. |
196
+ | `--blur` | 3 | Denoising blur before thresholding (0 turns it off). |
197
+ | `-u, --upscale` | auto | Enlarge the image before tracing. By default, small anti-aliased mono images are upscaled up to 4×. |
198
+ | `--crop / --no-crop` | off | Trim empty margins. |
199
+ | `--padding` | 0 | Margin kept around cropped content, in pixels. |
200
+ | `-c, --color` | `auto` | Mono fill colour. `auto` keeps the source's ink colour. |
201
+ | `-b, --background` | none | Add a solid background. Output is transparent by default. |
202
+ | `--outline / --fill` | fill | Draw strokes instead of filled shapes. |
203
+ | `--stroke-width` | 1 | Stroke width for `--outline`, in pixels. |
204
+ | `--turdsize` | 5 | [mono] Remove specks up to this area, in pixels. |
205
+ | `--alphamax` | 0.9 | [mono] Corner smoothing, from 0 (sharp) to 1.334 (round). |
206
+ | `--opttolerance` | 0.2 | [mono] How aggressively curves are merged. |
207
+ | `--colors` | 6 | [color] Colour precision in bits per channel (1–8). |
208
+ | `--filter-speckle` | 4 | [color] Discard patches smaller than this. |
209
+ | `--layer-difference` | 16 | [color] Minimum colour difference between layers. |
210
+ | `--trace-mode` | `spline` | [color] `spline`, `polygon`, or `none` (pixel-exact). |
211
+ | `--optimize / --no-optimize` | on | Minify the SVG with Scour. |
212
+ | `--preview` | off | Also write a PNG rendering of the result. |
213
+ | `--json` | off | Print machine-readable results. |
214
+ | `-q, --quiet` | off | Only print errors. |
215
+
216
+ ## How it works
217
+
218
+ 1. **Load.** Pillow reads the image, with EXIF rotation, 16-bit images and transparency all handled. Transparent images are composited onto whichever background contrasts with the content, so both dark and light logos on transparency come out right.
219
+ 2. **Prepare (mono).** vecto converts to greyscale and upscales small images, but only anti-aliased ones, where there's sub-pixel detail to recover. It then blurs lightly, thresholds (Otsu, manual or adaptive), detects a dark background, and optionally crops.
220
+ 3. **Trace.** Mono images go through potrace (pure-Python [`potracer`](https://pypi.org/project/potracer/)). Colour images go through [`vtracer`](https://github.com/visioncortex/vtracer).
221
+ 4. **Optimise.** [Scour](https://github.com/scour-project/scour) minifies the SVG. The output keeps the source's pixel dimensions, plus a `viewBox`.
222
+ 5. **Score.** [resvg](https://github.com/linebender/resvg) renders the result, which is compared against the source (see *Fidelity* above).
223
+
224
+ ## License
225
+
226
+ [MIT](LICENSE)
@@ -0,0 +1,196 @@
1
+ # vecto
2
+
3
+ Turn PNG, JPG and WebP images into clean, small SVGs, and find out how accurate each one is.
4
+
5
+ `vecto` traces logos, icons, signatures, line art, colour illustrations and pixel art. It also makes cut files for Cricut, Silhouette, laser cutters and plotters. You can use it as a **CLI**, a **Python library**, or an **MCP server** that AI assistants call directly.
6
+
7
+ - **Presets instead of knobs.** Pick `logo`, `signature`, `cut`, `pixel` and so on instead of tuning potrace settings.
8
+ - **Every result is scored.** vecto renders the SVG back to pixels and compares it with the source, so you can see how faithful the trace is.
9
+ - **`--auto` tuning.** It searches tracing settings for the *smallest* SVG that still matches the source.
10
+ - **Handles real inputs.** It deals with transparent PNGs, light-on-dark images, tiny low-resolution logos, phone photos of signatures and dusty scans.
11
+ - **No system dependencies.** Every dependency installs from pip wheels on Linux, macOS and Windows. You don't need the `potrace` binary or Cairo.
12
+
13
+ ## Examples
14
+
15
+ | Input | Command | Output (SVG) |
16
+ | --- | --- | --- |
17
+ | <img src="examples/logo.png" width="200"> 200×80 transparent PNG | `vecto convert logo.png -p logo --auto` | <img src="examples/out/logo.svg" width="200"><br>3.0 KB · fidelity 98.3% · edge error 0.24 px |
18
+ | <img src="examples/signature.jpg" width="240"> phone photo, uneven light, dust | `vecto convert signature.jpg -p signature` | <img src="examples/out/signature.svg" width="240"><br>3.3 KB · transparent · keeps the ink colour |
19
+ | <img src="examples/art.png" width="200"> flat illustration | `vecto convert art.png -p color` | <img src="examples/out/art.svg" width="200"><br>2.3 KB · 6 colours · fidelity 99.6% |
20
+ | <img src="examples/pixel.png" width="128" style="image-rendering:pixelated"> 16×16 sprite | `vecto convert pixel.png -p pixel` | <img src="examples/out/pixel.svg" width="128"><br>2.0 KB · pixel-exact |
21
+ | <img src="examples/logo.png" width="200"> | `vecto convert logo.png -p cut --outline` | <img src="examples/out/logo-cut.svg" width="200"><br>cut lines for a laser or plotter |
22
+
23
+ The example inputs are synthetic and generated by [`examples/make_examples.py`](examples/make_examples.py).
24
+
25
+ ## Install
26
+
27
+ vecto needs Python 3.12 or newer.
28
+
29
+ ```bash
30
+ uv tool install git+https://github.com/hugoogb/vecto
31
+ ```
32
+
33
+ You can use pipx instead:
34
+
35
+ ```bash
36
+ pipx install git+https://github.com/hugoogb/vecto
37
+ ```
38
+
39
+ To use the MCP server, install the `mcp` extra:
40
+
41
+ ```bash
42
+ uv tool install "vecto-svg[mcp] @ git+https://github.com/hugoogb/vecto"
43
+ ```
44
+
45
+ The package is called `vecto-svg` because `vecto` is already taken on PyPI. The command is still `vecto`.
46
+
47
+ For development:
48
+
49
+ ```bash
50
+ git clone https://github.com/hugoogb/vecto && cd vecto
51
+ uv sync --all-extras
52
+ uv run pytest
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ ### Convert one image
58
+
59
+ ```bash
60
+ vecto convert input.png # writes input.svg
61
+ vecto convert input.png out.svg -p logo # use a preset
62
+ vecto convert input.png --auto # smallest SVG that still matches
63
+ vecto convert input.png --preview # also writes out.preview.png
64
+ ```
65
+
66
+ Each run prints a summary to stderr:
67
+
68
+ ```
69
+ input.svg: 176.75x64, 3.0 KB, 1 paths, fidelity 98.3%, edge error 0.24px, 18 settings tried
70
+ ```
71
+
72
+ ### Pipes and scripts
73
+
74
+ Use `-` for stdin or stdout. Add `--json` to get machine-readable results.
75
+
76
+ ```bash
77
+ curl -s https://example.com/logo.png | vecto convert - -p logo > logo.svg
78
+ vecto convert logo.png logo.svg --json | jq '.fidelity, .bytes'
79
+ ```
80
+
81
+ ### Convert a folder
82
+
83
+ `batch` accepts every `convert` option. Without `--jobs` it uses one worker per CPU. One broken file doesn't stop the batch: failures are listed at the end, and the exit code is non-zero if any file failed.
84
+
85
+ ```bash
86
+ vecto batch ./images ./svgs -p icon --recursive --jobs 8
87
+ vecto batch ./scans ./out -p signature --skip-existing --json > report.json
88
+ ```
89
+
90
+ ### Presets
91
+
92
+ Run `vecto presets` to list them:
93
+
94
+ | Preset | For |
95
+ | --- | --- |
96
+ | `logo` | Flat logos and wordmarks. Keeps the ink colour, smooth curves, tight crop. |
97
+ | `icon` | Small icons and glyphs. Upscales aggressively before tracing. |
98
+ | `signature` | Scanned or photographed signatures and handwriting. Handles uneven paper, removes dust, transparent background. |
99
+ | `lineart` | Ink drawings, sketches and comics in black and white. |
100
+ | `cut` | Cutting machines (Cricut, Silhouette, laser, plotter). One colour, no specks, simplified paths. Add `--outline` for stroke-only cut lines. |
101
+ | `color` | Colour illustrations, flat artwork and stickers. |
102
+ | `photo` | Photographs, with a posterised look. |
103
+ | `pixel` | Pixel art. Keeps hard square pixels. |
104
+
105
+ Any option you set overrides the preset. For example, `-p cut --turdsize 5` keeps smaller details.
106
+
107
+ ### Fidelity and `--auto`
108
+
109
+ After tracing, vecto renders the SVG and compares it with the source.
110
+
111
+ - **Mono** results get two numbers:
112
+ - **fidelity** is the intersection-over-union of the ink pixels. Unlike plain pixel accuracy, it isn't inflated by empty background. Specks that were removed on purpose (see `--turdsize`) don't count against it.
113
+ - **edge error** is how far the outlines drift from the source, in pixels (99th percentile). Area scores barely notice rounded corners, but edge error does.
114
+ - **Colour** results get one number: 1 minus the mean colour difference.
115
+
116
+ `--auto` tries different curve-fitting settings (`alphamax` and `opttolerance` for mono, `colors` and `layer_difference` for colour). It keeps the **smallest file** that meets `--target` (default 0.95 mono, 0.98 colour) and, for mono, `--max-edge` (default 0.5 px). If no setting qualifies, it returns the most faithful result with a warning. Noise filtering is never auto-tuned. A search that rewards fidelity would always choose to keep the dust.
117
+
118
+ ### Use from Python
119
+
120
+ ```python
121
+ from vecto import vectorize, build_options
122
+
123
+ result = vectorize("logo.png", build_options("logo"), auto=True)
124
+ print(result.fidelity, result.edge_error, result.bytes)
125
+ open("logo.svg", "w").write(result.svg)
126
+
127
+ # numpy arrays (RGB, RGBA or greyscale) and raw bytes work too
128
+ result = vectorize(image_array, build_options("cut", turdsize=10))
129
+ ```
130
+
131
+ ### Use from AI assistants (MCP)
132
+
133
+ `vecto mcp` starts a stdio MCP server with two tools: `vectorize_image` and `list_presets`. The tool returns fidelity, size and warnings, so an agent can check the result instead of guessing.
134
+
135
+ To add it to Claude Code:
136
+
137
+ ```bash
138
+ claude mcp add vecto -- uvx --from "vecto-svg[mcp] @ git+https://github.com/hugoogb/vecto" vecto mcp
139
+ ```
140
+
141
+ For Claude Desktop, Cursor and other MCP clients, add this to the MCP config:
142
+
143
+ ```json
144
+ {
145
+ "mcpServers": {
146
+ "vecto": {
147
+ "command": "uvx",
148
+ "args": ["--from", "vecto-svg[mcp] @ git+https://github.com/hugoogb/vecto", "vecto", "mcp"]
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+ ## Options
155
+
156
+ | Option | Default | Description |
157
+ | --- | --- | --- |
158
+ | `-p, --preset` | none | Start from a preset (see above). |
159
+ | `-m, --mode` | `mono` | `mono` traces one colour with potrace. `color` traces colour layers with vtracer. |
160
+ | `--auto` | off | Search for the smallest SVG that meets `--target` and `--max-edge`. |
161
+ | `--target` | 0.95 / 0.98 | Fidelity goal for `--auto`. |
162
+ | `--max-edge` | 0.5 | [mono] Maximum edge drift for `--auto`, in pixels. |
163
+ | `-t, --threshold` | auto (Otsu) | Cut-off between ink and background (0–255). |
164
+ | `--adaptive` | off | Local thresholding, for shadows and uneven paper. |
165
+ | `--invert / --no-invert` | auto | Swap ink and background. By default, dark backgrounds are detected automatically. |
166
+ | `--blur` | 3 | Denoising blur before thresholding (0 turns it off). |
167
+ | `-u, --upscale` | auto | Enlarge the image before tracing. By default, small anti-aliased mono images are upscaled up to 4×. |
168
+ | `--crop / --no-crop` | off | Trim empty margins. |
169
+ | `--padding` | 0 | Margin kept around cropped content, in pixels. |
170
+ | `-c, --color` | `auto` | Mono fill colour. `auto` keeps the source's ink colour. |
171
+ | `-b, --background` | none | Add a solid background. Output is transparent by default. |
172
+ | `--outline / --fill` | fill | Draw strokes instead of filled shapes. |
173
+ | `--stroke-width` | 1 | Stroke width for `--outline`, in pixels. |
174
+ | `--turdsize` | 5 | [mono] Remove specks up to this area, in pixels. |
175
+ | `--alphamax` | 0.9 | [mono] Corner smoothing, from 0 (sharp) to 1.334 (round). |
176
+ | `--opttolerance` | 0.2 | [mono] How aggressively curves are merged. |
177
+ | `--colors` | 6 | [color] Colour precision in bits per channel (1–8). |
178
+ | `--filter-speckle` | 4 | [color] Discard patches smaller than this. |
179
+ | `--layer-difference` | 16 | [color] Minimum colour difference between layers. |
180
+ | `--trace-mode` | `spline` | [color] `spline`, `polygon`, or `none` (pixel-exact). |
181
+ | `--optimize / --no-optimize` | on | Minify the SVG with Scour. |
182
+ | `--preview` | off | Also write a PNG rendering of the result. |
183
+ | `--json` | off | Print machine-readable results. |
184
+ | `-q, --quiet` | off | Only print errors. |
185
+
186
+ ## How it works
187
+
188
+ 1. **Load.** Pillow reads the image, with EXIF rotation, 16-bit images and transparency all handled. Transparent images are composited onto whichever background contrasts with the content, so both dark and light logos on transparency come out right.
189
+ 2. **Prepare (mono).** vecto converts to greyscale and upscales small images, but only anti-aliased ones, where there's sub-pixel detail to recover. It then blurs lightly, thresholds (Otsu, manual or adaptive), detects a dark background, and optionally crops.
190
+ 3. **Trace.** Mono images go through potrace (pure-Python [`potracer`](https://pypi.org/project/potracer/)). Colour images go through [`vtracer`](https://github.com/visioncortex/vtracer).
191
+ 4. **Optimise.** [Scour](https://github.com/scour-project/scour) minifies the SVG. The output keeps the source's pixel dimensions, plus a `viewBox`.
192
+ 5. **Score.** [resvg](https://github.com/linebender/resvg) renders the result, which is compared against the source (see *Fidelity* above).
193
+
194
+ ## License
195
+
196
+ [MIT](LICENSE)
Binary file
Binary file
@@ -0,0 +1,95 @@
1
+ """Generate the sample inputs used in the README (synthetic, reproducible).
2
+
3
+ uv run python examples/make_examples.py
4
+ """
5
+
6
+ from pathlib import Path
7
+
8
+ import cv2
9
+ import numpy as np
10
+ from PIL import Image
11
+
12
+ HERE = Path(__file__).parent
13
+ rng = np.random.default_rng(7)
14
+
15
+
16
+ def supersample(draw, w, h, channels, ss=8, bg=0):
17
+ """Draw at ss x resolution and downsample, giving realistic anti-aliasing."""
18
+ big = np.full((h * ss, w * ss, channels), bg, np.uint8)
19
+ draw(big, ss)
20
+ return cv2.resize(big, (w, h), interpolation=cv2.INTER_AREA)
21
+
22
+
23
+ def logo():
24
+ # Small transparent logo (anti-aliased), the kind people grab from a website.
25
+ def draw(img, s):
26
+ navy = (32, 46, 120, 255)
27
+ cv2.circle(img, (40 * s, 40 * s), 30 * s, navy, -1, cv2.LINE_AA)
28
+ cv2.circle(img, (40 * s, 40 * s), 17 * s, (0, 0, 0, 0), -1, cv2.LINE_AA)
29
+ pts = np.array([[28, 62], [40, 18], [52, 62]], np.int32) * s
30
+ cv2.fillPoly(img, [pts], navy, cv2.LINE_AA)
31
+ cv2.putText(img, "vecto", (78 * s, 54 * s), cv2.FONT_HERSHEY_DUPLEX, 1.25 * s,
32
+ navy, 3 * s, cv2.LINE_AA)
33
+ rgba = supersample(draw, 200, 80, 4)
34
+ Image.fromarray(rgba, "RGBA").save(HERE / "logo.png")
35
+
36
+
37
+ def signature():
38
+ # Blue ink on off-white paper, photographed: uneven light, grain, JPEG.
39
+ w, h = 600, 260
40
+
41
+ def draw(img, s):
42
+ t = np.linspace(0, 1, 400)
43
+ x = 60 + 470 * t
44
+ y = 140 + 45 * np.sin(t * 19) * np.exp(-t * 1.2) - 30 * np.sin(t * 5)
45
+ pts = np.stack([x, y], 1) * s
46
+ cv2.polylines(img, [pts.astype(np.int32)], False, (25, 40, 150), 4 * s, cv2.LINE_AA)
47
+ loop = np.stack([140 + 40 * np.cos(np.linspace(0, 6.3, 120)),
48
+ 120 + 70 * np.sin(np.linspace(0, 6.3, 120))], 1) * s
49
+ cv2.polylines(img, [loop.astype(np.int32)], False, (25, 40, 150), 3 * s, cv2.LINE_AA)
50
+ cv2.line(img, (90 * s, 205 * s), (520 * s, 195 * s), (25, 40, 150), 3 * s, cv2.LINE_AA)
51
+
52
+ ink = supersample(draw, w, h, 3, bg=255).astype(np.float32)
53
+ yy, xx = np.mgrid[0:h, 0:w]
54
+ light = 0.62 + 0.38 * np.clip(1 - ((xx - 150) ** 2 + (yy - 40) ** 2) / 420_000, 0, 1)
55
+ paper = np.array([242, 236, 222], np.float32) * light[..., None]
56
+ img = paper * (ink / 255.0) + rng.normal(0, 6, (h, w, 3))
57
+ for _ in range(40): # dust
58
+ cv2.circle(img, (int(rng.integers(w)), int(rng.integers(h))), 1, (90, 90, 90), -1)
59
+ img = np.clip(img, 0, 255).astype(np.uint8)
60
+ Image.fromarray(img).save(HERE / "signature.jpg", quality=80)
61
+
62
+
63
+ def art():
64
+ # Flat colour illustration.
65
+ def draw(img, s):
66
+ img[:] = (170, 215, 245)
67
+ cv2.circle(img, (230 * s, 70 * s), 38 * s, (250, 200, 60), -1, cv2.LINE_AA)
68
+ cv2.ellipse(img, (90 * s, 260 * s), (190 * s, 110 * s), 0, 0, 360, (90, 170, 90), -1, cv2.LINE_AA)
69
+ cv2.ellipse(img, (260 * s, 280 * s), (170 * s, 100 * s), 0, 0, 360, (60, 130, 70), -1, cv2.LINE_AA)
70
+ cv2.rectangle(img, (70 * s, 150 * s), (84 * s, 200 * s), (110, 75, 45), -1)
71
+ cv2.circle(img, (77 * s, 135 * s), 30 * s, (40, 110, 55), -1, cv2.LINE_AA)
72
+ rgb = supersample(draw, 320, 240, 3)
73
+ Image.fromarray(rgb).save(HERE / "art.png")
74
+
75
+
76
+ def pixel():
77
+ # 16x16 sprite.
78
+ palette = {".": (0, 0, 0, 0), "k": (30, 30, 40, 255), "r": (220, 50, 60, 255),
79
+ "w": (255, 255, 255, 255), "p": (250, 150, 160, 255)}
80
+ rows = [
81
+ "................", "...kk......kk...", "..krrk....krrk..", ".krrrrk..krrrrk.",
82
+ ".krwrrrkkrrrrrk.", ".krwrrrrrrrrrrk.", ".krrrrrrrrrrrrk.", ".krrrrrrrrrrprk.",
83
+ "..krrrrrrrrrpk..", "...krrrrrrrrk...", "....krrrrrrk....", ".....krrrrk.....",
84
+ "......krrk......", ".......kk.......", "................", "................",
85
+ ]
86
+ img = np.array([[palette[c] for c in row] for row in rows], np.uint8)
87
+ Image.fromarray(img, "RGBA").save(HERE / "pixel.png")
88
+
89
+
90
+ if __name__ == "__main__":
91
+ logo()
92
+ signature()
93
+ art()
94
+ pixel()
95
+ print("wrote", ", ".join(p.name for p in sorted(HERE.glob("*.*")) if p.suffix != ".py"))
Binary file
Binary file
@@ -0,0 +1,55 @@
1
+ [project]
2
+ name = "vecto-svg"
3
+ version = "0.2.0"
4
+ description = "Turn PNG/JPG images into clean, small SVGs: logos, icons, signatures, cut files, colour art. CLI, Python API and MCP server."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ keywords = ["svg", "vectorize", "vectorizer", "potrace", "trace", "bitmap", "png-to-svg", "cricut", "laser", "mcp"]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Environment :: Console",
13
+ "Intended Audience :: Developers",
14
+ "Intended Audience :: End Users/Desktop",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Topic :: Multimedia :: Graphics :: Graphics Conversion",
20
+ ]
21
+ dependencies = [
22
+ "opencv-python-headless>=4.10",
23
+ "pillow>=11",
24
+ "potracer>=0.0.4",
25
+ "resvg-py>=0.5.0",
26
+ "scour>=0.38.2",
27
+ "typer>=0.15",
28
+ "vtracer>=0.6.15",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ mcp = ["mcp>=1.2"]
33
+
34
+ [project.scripts]
35
+ vecto = "vecto.cli:app"
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/hugoogb/vecto"
39
+ Issues = "https://github.com/hugoogb/vecto/issues"
40
+
41
+ [build-system]
42
+ requires = ["hatchling"]
43
+ build-backend = "hatchling.build"
44
+
45
+ [tool.hatch.build.targets.sdist]
46
+ exclude = ["examples/out", ".github"]
47
+
48
+ [dependency-groups]
49
+ dev = ["pytest>=8"]
50
+
51
+ [tool.pytest.ini_options]
52
+ testpaths = ["tests"]
53
+
54
+ [tool.hatch.build.targets.wheel]
55
+ packages = ["vecto"]
File without changes
@@ -0,0 +1,42 @@
1
+ from pathlib import Path
2
+
3
+ import cv2
4
+ import numpy as np
5
+ import pytest
6
+ from PIL import Image
7
+
8
+
9
+ def ring(size=200, aa=True, fg=(0, 0, 0), bg=(255, 255, 255)) -> np.ndarray:
10
+ line = cv2.LINE_AA if aa else cv2.LINE_8
11
+ img = np.zeros((size, size, 3), np.uint8)
12
+ img[:] = bg
13
+ c, r = size // 2, int(size * 0.35)
14
+ cv2.circle(img, (c, c), r, fg, -1, line)
15
+ cv2.circle(img, (c, c), r // 2, bg, -1, line)
16
+ return img
17
+
18
+
19
+ @pytest.fixture
20
+ def ring_png(tmp_path) -> Path:
21
+ p = tmp_path / "ring.png"
22
+ Image.fromarray(ring()).save(p)
23
+ return p
24
+
25
+
26
+ @pytest.fixture
27
+ def transparent_white_logo(tmp_path) -> Path:
28
+ rgba = np.zeros((96, 96, 4), np.uint8)
29
+ cv2.circle(rgba, (48, 48), 30, (255, 255, 255, 255), -1, cv2.LINE_AA)
30
+ p = tmp_path / "white.png"
31
+ Image.fromarray(rgba, "RGBA").save(p)
32
+ return p
33
+
34
+
35
+ @pytest.fixture
36
+ def color_png(tmp_path) -> Path:
37
+ img = np.full((120, 160, 3), 255, np.uint8)
38
+ cv2.circle(img, (50, 60), 35, (210, 40, 40), -1, cv2.LINE_AA)
39
+ cv2.rectangle(img, (95, 20), (150, 100), (40, 110, 220), -1)
40
+ p = tmp_path / "color.png"
41
+ Image.fromarray(img).save(p)
42
+ return p