Example Apps
All DocsOne conversion pipeline - filter, segment, trace - run from every binding. The browser apps are live: upload a raster image, get an SVG back, and see the exact code that did it. The console apps run the same pipeline from the command line in C, C++, Python, and JavaScript. Pick whichever matches your stack and copy it as a starting point.
React color-by-number demo
example-apps/react-jsFull interactive demo, bundled with Vite - the setup most web apps use.
import { imageToUint8ClampedArray, imageToSvg } from "img2num";
const { pixels, width, height } = await imageToUint8ClampedArray(file);
const { svg } = await imageToSvg({ pixels, width, height });
HTML + ES Modules
example-apps/html-jsThe browser ESM build loaded natively. No bundler, no build step.
<script type="module">
import { imageToUint8ClampedArray, imageToSvg }
from "https://cdn.jsdelivr.net/npm/img2num/dist/browser/img2num.js";
// ...
</script>
HTML + IIFE
example-apps/html-jsOne plain script tag, one global object. The simplest integration.
<script src="https://cdn.jsdelivr.net/npm/img2num/dist/standalone/img2num.iife.js"></script>
<script>
const { imageToUint8ClampedArray, imageToSvg } = Img2Num;
// ...
</script>
HTML + UMD (RequireJS)
example-apps/html-jsLoaded as an AMD module - nothing is added to the global scope.
requirejs.config({ paths: { img2num: ".../dist/standalone/img2num.umd" } });
requirejs(["img2num"], ({ imageToUint8ClampedArray, imageToSvg }) => {
// ...
});
console-js-esm
example-apps/console-js-esmThe same WASM build in Node.js: decode with sharp, convert with imageToSvg.
import { imageToSvg } from "img2num";
import sharp from "sharp";
const { data, info } = await sharp(imagePath).ensureAlpha().raw()
.toBuffer({ resolveWithObject: true });
const { svg } = await imageToSvg({ pixels: new Uint8ClampedArray(data.buffer), ...info });
console-js-cjs
example-apps/console-js-cjsIdentical to the ESM app, consumed with require() from CommonJS.
const { imageToSvg } = require("img2num");
const sharp = require("sharp");
// ... decode, then:
const { svg } = await imageToSvg({ pixels, width, height });
console-py
example-apps/console-pyOpenCV image in, SVG out with numpy zero-copy.
import img2num
cfg = img2num.ImageToSvgConfig(kmeans={"k": 64}, min_thickness=10)
svg = img2num.image_to_svg(img, config=cfg)
console-cpp
example-apps/console-cppThe native core: step-by-step pipeline and the unified call.
img2num::ImageToSvgConfig config;
config.kmeans.k = 32;
std::string svg {img2num::image_to_svg(img_data, width, height, config)};
console-c
example-apps/console-cThe C bindings with stb_image: filter, k-means, SVG output.
img2num_ImageToSvgConfig cfg = img2num_ImageToSvgConfig_default();
char* svg = img2num_image_to_svg(image_data, width, height, &cfg);
Each browser example page shows its complete code, and the plain-HTML apps are fully standalone - use your browser's View Source to see the whole page. All example source and build setup lives in example-apps/ on GitHub.