mirror of
https://github.com/visioncortex/vtracer.git
synced 2026-08-31 01:15:57 -07:00
a350e2532a
BinaryFrontend gains a Threshold enum: Fixed(u8) (now tunable, was
hardcoded to 128) and Adaptive { window, t } — Bradley–Roth adaptive
thresholding computed via visioncortex's SummedAreaTable, O(pixels)
regardless of window size, for images with uneven lighting. Both use a
shared (r+g+b)/3 intensity so they agree on "dark"; the grayscale
checker_bw golden is unaffected.
Exposed through Config and all bindings: CLI (--threshold, --adaptive,
--adaptive-window, --adaptive-t), Python (constructor kwargs + getters/
setters), and the Node package (binaryThreshold, adaptive, adaptiveWindow,
adaptiveT). Adds tests covering fixed tunability and adaptive recovering
locally-dark marks under a brightness gradient that a global cutoff can't.
vtracer (Node.js)
Raster → vector (SVG) for Node, a WebAssembly build of the
vtracer framework. Image decoding
and vectorization both happen in wasm, so there is no native dependency —
just npm install.
Install
npm install @visioncortex/vtracer
Usage
const vtracer = require('@visioncortex/vtracer');
// file in, file out
await vtracer.convertFile('in.png', 'out.svg');
await vtracer.convertFile('in.jpg', 'out.svg', { mode: 'polygon', hierarchical: 'cutout' });
// buffers
const svg = vtracer.convertBuffer(fs.readFileSync('in.png'), { preset: 'poster' });
// raw RGBA8 pixels
const svg2 = vtracer.convertPixels(rgba, width, height, { colorMode: 'bw' });
API
convertBuffer(buffer, options?) => string— encoded image (PNG/JPEG/GIF/BMP) → SVG.convertPixels(rgba, width, height, options?) => string— raw RGBA8 → SVG.convertFile(input, output, options?) => Promise<void>— read, trace, write.convertFileSync(input, output, options?) => void.
Options (all optional, camelCase)
preset ("bw" | "poster" | "photo", applied first), colorMode
("color" | "bw"), hierarchical ("stacked" | "cutout" for the seam-free
mosaic), mode ("pixel" | "polygon" | "spline"), filterSpeckle,
colorPrecision, layerDifference, cornerThreshold, lengthThreshold,
maxIterations, spliceThreshold, pathPrecision, palette (list of
#rrggbb), maxColors, optimize (0 | 1 | 2).
Build from source
Requires the Rust toolchain and wasm-pack:
npm run build # wasm-pack build --target nodejs --out-dir pkg
npm test