A simple Node.js library to convert raster images into svg using VTracer, with time complexity of O(n)
.
npm install @neplex/vectorizer
import {
vectorize,
ColorMode,
Hierarchical,
PathSimplifyMode,
} from '@neplex/vectorizer';
import { readFile, writeFile } from 'node:fs/promises';
const src = await readFile('./raster.png');
const svg = await vectorize(src, {
colorMode: ColorMode.Color,
colorPrecision: 6,
filterSpeckle: 4,
spliceThreshold: 45,
cornerThreshold: 60,
hierarchical: Hierarchical.Stacked,
mode: PathSimplifyMode.Spline,
layerDifference: 5,
lengthThreshold: 5,
maxIterations: 2,
pathPrecision: 5,
});
console.log(svg); // <svg>...</svg>
await writeFile('./vector.svg', svg);
If you want to use synchronous API, you can use vectorizeSync
instead.
Takes an image buffer and returns a promise that resolves to an SVG string.
Takes an image buffer and returns an SVG string synchronously.
Takes a raw pixel data buffer and returns a promise that resolves to an SVG string.
Takes a raw pixel data buffer and returns an SVG string synchronously.
Generated under the following configuration:
{
colorMode: ColorMode.Color,
colorPrecision: 8,
filterSpeckle: 4,
spliceThreshold: 45,
cornerThreshold: 60,
hierarchical: Hierarchical.Stacked,
mode: PathSimplifyMode.Spline,
layerDifference: 6,
lengthThreshold: 4,
maxIterations: 2
}
Raster Image (PNG Input) | Vector Image (Generated SVG) |
---|---|
CC-BY-SA 3.0 by Niabot |
CC-BY-SA 3.0 by Niabot |