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 🙏

© 2025 – Pkg Stats / Ryan Hefner

imagetrace

v1.2.2

Published

A simple TypeScript library for converting raster images to vector graphics.

Readme

imagetrace

A simple TypeScript library for converting raster images to vector graphics, given the set of colours to trace for. This library is meant for flat, organic, 2D shapes with a uniform colour. I built this package to be used with the output of a shader script.

Version License TypeScript

npm: https://www.npmjs.com/package/imagetrace

Features

  • 🔄 Raster to vector conversion
  • 🎯 Color-based region detection
  • 🎨 Blob detection algorithm
  • 🤹 Blob separation algorithm
  • ✒️ Point visualization option
  • 💪 TypeScript type safety

Example

| Input PNG | Output SVG | | :--------------------------: | :----------------------------------: | | Input | Output | | Input | Output |

The example above shows the conversion from a raster PNG image (left) to a vectorized SVG output (right). Notice how the library:

  • Detects color regions
  • Preserves shapes
  • Creates simple vector paths
  • Skips holes ⚠️
  • Gives an option for viewing the path points: the simplified polygon (stroked black) and bezier points (filled black)

Installation

npm install imagetrace

Quick Start

import { ImageTrace } from 'imagetrace';

// get image data from a canvas or blob
const imageData = canvasContext.getImageData();

// define the color palette for the shapes you want to trace
const palette = [
	{ r: 255, g: 0, b: 0 }, // red
	{ r: 0, g: 0, b: 255 }, // blue
];

// configure the tracer
const options = {
	chaikinSmoothingSteps: 5,
	smoothingMinLength: 5,
	pixelGridStepSize: 1,
	debugPointRadius: undefined,
};

// create a new tracer instance
const tracer = new ImageTrace(imageData, palette, options);

// get SVG output
const svg = tracer.getSVGString();

API Reference

ImageTrace

Main class for converting raster images to vector graphics.

new ImageTrace(
    imageData: ImageDataLike,
    palette: Color[],
    options: ImageTraceOptions
)

Options

| Option | Type | Default | Description | | --------------------- | ------ | --------- | ------------------------------------ | | smoothingMinLength | number | - | Minimum length for path smoothing | | chaikinSmoothingSteps | number | - | Number of smoothing iterations | | pixelGridStepSize | number | 1 | Pixel point cloud sampling interval | | debugPointRadius | number | undefined | Radius for debug point visualization |

Development

Prerequisites

  • Node.js 14+
  • npmnode

Setup

# install via npm
npm install imagetrace

Building a clone

npm run build

Testing

npm test

Basic Usage

import { ImageTrace } from 'imagetrace';

// load your image data
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const imageData = ctx.getImageData(0, 0, width, height);

// create tracer instance for yellow shapes
const tracer = new ImageTrace(imageData, [{ r: 255, g: 255, b: 0 }], {
	pathSimplificationTolerance: 3,
	curveFittingTolerance: 2,
	minHullDistance: 3,
});

// get SVG output
const svg = tracer.getSVGString();

Credits

Dependencies

  • concaveman - A fast 2D concave hull algorithm by Vladimir Agafonkin (@mourner)

Inspirations

Contributing

Contributions are welcome!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Performance Notes

  • Processing time varies with image size and complexity
  • For optimal performance, consider:
    • Adjusting pixelGridStepSize for larger images
    • Tuning smoothingMinLength based on image size
    • Running locally rather than in web-based environments

Support

  • Create an issue in the GitHub repository

Roadmap

  • [ ] More detailed smoothing options
  • [ ] Automatic SVG download