npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cv-trace

v0.2.3

Published

A library for tracing images to SVG

Downloads

9

Readme

cv-trace

A library for tracing images to SVG

npm version License: GPL v2

Install

npm install cv-trace
# or
pnpm add cv-trace

Start quickly

import { readFileSync, writeFileSync } from "fs";
import { binaryPreprocess, potrace, svgoOptimize } from "cv-trace";
import type { BinaryOptions } from "cv-trace";
// 1. Binary preprocessing
const layerData = await binaryPreprocess(imageBuffer, {
  threshold: [128, 255],
  color: "#000000",
} as BinaryOptions);
// 2. Vectorize with potrace
const result = await potrace(layerData);
// 3. Optimize SVG (optional)
result.svg = await svgoOptimize(result.svg);
writeFileSync("./output.svg", result.svg);
writeFileSync("./preview.png", result.preprocessedImage);
import { readFileSync, writeFileSync } from "fs";
import { quantizePreprocess, potrace, svgoOptimize } from "cv-trace";
import type { QuantizeOptions } from "cv-trace";
const imageBuffer = readFileSync("./test1.jpg");
// 1. Color quantization preprocessing  
const layerData = await quantizePreprocess(imageBuffer, {
  colorCount: 16,
  minPercent: 0,
  stack: true,
} as QuantizeOptions);
// 2. Vectorize with potrace
const result = await potrace(layerData);
// 3. Optimize SVG (optional)
result.svg = await svgoOptimize(result.svg);
writeFileSync("./output1.svg", result.svg);
writeFileSync("./preview1.png", result.preprocessedImage);

CommonJS : const { binaryPreprocess, potrace, optimizeSvg } = require("cv-trace");

Example

| Original Image | Preprocessed Image | Vector Result | | :--------------------------: | :--------------------------------: | :------------------------------: | | test0.jpg | preview0.png | output0.svg | | test.jpg | preview.png | output.svg | | test1.jpg | preview1.png | output1.svg |

Core

Type

export type Layer = {
  id: string;
  zIndex: number;
  color: string;
  imageBuffer: Buffer;
}

export type OriginalMetadata = {
  width: number;
  height: number;
  format?: string;
}

export type LayerData = {
  layers: Layer[];
  preprocessedImage: Buffer;
  originalMetadata: OriginalMetadata;
}

export type VectorizeResult = {
  svg: string;
  preprocessedImage: Buffer;
  originalMetadata: OriginalMetadata;
}

Process Flow

(Image Buffer) --preprocess--> (LayerData) --trace--> (VectorizeResult) -- optimizer--> (VectorizeResult)

flowchart LR
    A[Image Buffer] --> B{Preprocess}
    B --> C[LayerData]
    C --> D{Trace}
    D --> E[VectorizeResult]
    E --> F{Optimizer}
    F --> G[Optimized SVG]

    B -.-> H[Preview Image]

Preprocess

Use Preprocessor to convert Image Buffer to LayerData ( with preprocessedImage for Preview )

Preprocessor

Convert the original image to layers of black and white binary image masks (Buffer), and carry layer and color information (although non-binary images are also supported, it is recommended to convert to binary images, because this provides better control)

Plan to support more Preprocessor in the future. And quantization according to color will be preferred (Actually, color quantization has been implemented, but we are thinking about how to make the code more elegant)

Trace

Tracer

Currently uses potrace to convert LayerData to a hierarchical SVG image

Plan to support more tracers in the future

Optimizer

Plan to use svgo to optimize svg string

Credits

LICENSE

GPL-2.0-or-later

Potrace is GPL LICENSE