A modern ESM build of the Potrace library for use in the browser.
npm install esm-potrace-wasmA modern ESM build of the Potrace library for use in the browser.
``bash`
npm install --save esm-potrace-wasm
`js
import { potrace, init } from 'esm-potrace-wasm';
(async () => {
// Initialize the module once.
await init();
/**
* The imageBitmapSource parameter is an ImageBitmapSource, that is any of:HTMLImageElement
* - SVGImageElement
* - HTMLVideoElement
* - HTMLCanvasElement
* - ImageData
* - ImageBitmap
* - Blob
* - `
*/
const svg = await potrace(
imageBitmapSource,
(options = {
turdsize: 2,
turnpolicy: 4,
alphamax: 1,
opticurve: 1,
opttolerance: 0.2,
pathonly: false,
extractcolors: true,
posterizelevel: 2, // [1, 255]
posterizationalgorithm: 0, // 0: simple, 1: interpolation
})
);
})();
Modify src/potrace/ and run npm run build to update the ESM build in dist/../build.sh
The emscripten build file is located at (or build.ps1 for Win32) respectively. A simple demodist/index.js
that imports is available in demo/ and can be started by running npm start`.
This library is used in SVGcode.
⚠️ GPL-v2.0, due to the original Potrace license.
Based on @nturley's fork of
@IguteChung's initial potrace-wasm.
Unfortunately, the original author did not react on my
Pull Request, so I forked.