Skip to content

Repository files navigation

toSVG — Raster-to-SVG Vectorizer

Converts raster images into SVG with Potrace. Ships in two forms:

  • web/ — browser app, deployable to Netlify. Runs entirely client-side (Potrace compiled to WebAssembly); no server, no uploads.
  • root Python — CLI and Tkinter GUI driving the native potrace binary.

Both share the same pipeline; the web version is a port of the Python one and produces equivalent output.


Web app (Netlify)

Deploy

The repo is deploy-ready — netlify.toml at the root already points at web/:

base = "web", command = "npm run build", publish = "dist"
  1. Connect the repository on Netlify (or run netlify deploy --prod).
  2. No environment variables, no build plugins, no functions. Netlify runs npm run build inside web/ and serves the static dist/.

Netlify has no Python runtime and no potrace binary, so the web app is not a wrapper around the CLI: the whole pipeline (resampling, denoise, quantization, tracing) was reimplemented in JavaScript + WebAssembly and runs in the visitor's browser. Nothing is uploaded anywhere — the CSP in netlify.toml sets connect-src 'none', so the browser itself enforces that.

Local development

cd web
npm install
npm run dev       # http://localhost:5173
npm run build     # -> web/dist
npm run preview   # serve the production build

Notes

  • Work happens in Web Workers, several images in parallel; batch results download as a .zip.
  • Supersampling multiplies the traced area by . Above ~12 Mpx the factor is reduced automatically to keep the tab from running out of memory.
  • Speed is dominated by Potrace, which traces one layer per color. A 1200×900 photo at 16 colors takes roughly 12 s; lowering colors or setting supersample to 1 makes it several times faster.
  • Transparent PNGs are flattened onto white by default. Without that, dropping the alpha channel (what Pillow does) turns transparent areas into pure black and buries the trace under a black rectangle.

Python CLI / GUI

Requirements

  • Python 3.10+
  • potrace on your PATH — macOS: brew install potrace

Install

python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

Usage

GUI — add files or a whole folder, pick the output folder, click vectorize:

./vetorizar.sh gui      # or: python3 gui.py

CLI:

python3 cli.py --input ./photo.png --output ./out/photo.svg   # single
python3 cli.py --input ./images --output ./out                # folder

Useful options:

  • --colors 16 — color vectorization; 0 = black and white.
  • --threshold 160 — binarization (0–255); lower = more black.
  • --invert — invert binarization (if the trace comes out negative).
  • --turnpolicy minority — potrace turn policy (see potrace -h).

Input: anything Pillow can open (PNG/JPEG/WebP/TIFF…). Output: SVG from potrace.


License

Potrace is GPL-2.0, and so is the WebAssembly build bundled into the web app (esm-potrace-wasm). Distributing the built site therefore distributes GPL-2.0 code — keep the corresponding source available.

About

Imagem to SVG - Vetorizador de imagens

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages