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

potrace-plus

v0.1.3

Published

A javascript port of Peter Selinger's [Potrace](http://potrace.sourceforge.net). Based on [kilobtye's JS port](https://github.com/kilobtye/potrace)

Readme

potrace-plus

A javascript port of Peter Selinger's Potrace.
Based on kilobtye's JS port

Features

  • SVG optimization for smaller file sizes
  • convenient API accepting multiple input formats
    • DOM elements: <img>, <canvas> or <svg>
    • blob or file objects
    • URLs/dataURLs
  • filter options for preprocessing
  • cropping to actual image boundaries
  • splitting into separate paths – retaining compound shapes like "o"
  • shape sorting shapes are sorted from top-left to bottom-right
  • SVG optimizations colinear/flat segments are simplified
  • PDF export minimal standalone PDF export
  • polygon export ... erm Potrace is based on a polygon creation so why not retrieve the unoptimized polygon as a point object array as well?

Usage

Load script locally or via cdn

<script src="https://cdn.jsdelivr.net/npm/potrace-plus@latest/dist/potrace-plus.min.js"></script>

Call potrace in asynchronous function.

(async()=>{
    let traced = await PotracePlus(imgPreview);

    // retrieve all data
    let { svg, svgSplit, d, width, height, commands, pathData, pdf } = traced;

})();

ESM


import {PotracePlus} from './dist/potrace-plus.esm.min.js

(async()=>{
    let traced = await PotracePlus(imgPreview);
})();

The potrace object contains all relevant data:

  • SVG markup for self-contained file – split and single compound path
  • SVG path markup
  • SVG 2 pathData array – optimized and normalized (all absolute)
  • width and height
  • command count

You can also use these methods


// Get the SVG markup for compound or split paths
traced.getSVG(split=false)

// Get stringified path data - as `d` attribute
traced.getD()

// Get path data array
traced.getPathData()
traced.getPathDataNorm()

Options


let options = {
    /**
     * Potrace options
     * See: https://pythonhosted.org/pypotrace/ref.html
     */
    turnpolicy : "majority",
    turdsize : 1,
    optcurve : true,
    alphamax : 1,
    opttolerance : 1,

    // size adjustments
    minSize : 1000,
    maxSize : 5000,
    scale : 1,

    //filters
    brightness : 1,
    contrast : 1,
    invert : 0,
    blur=0,

    // svg processing
    crop : true,
    optimize = true,

    // add width and height attribute to SVG
    addDimensions : true,

    // SVG optimization
    toRelative : true,
    toShorthands : true,
    decimals : 3

    // get unoptimized polygon
    getPolygon = true,

    // get PDF data
    getPDF = true


}

let traced = await PotracePlus(imgPreview, options);

Path sorting

Paths and Subpaths are sorted in a more logical order from top-left to bottom right. This is foremost handy for manual editing the output in a graphic editor.

Path splitting/grouping

By default the tracing object contains

  • traced.svg a concatenated SVG file - all shapes are merged into a single path
  • traced.svgSplit a SVG with individual <path> elements for each "logical" shape group

For instance a text-like object "Pot" would return a path for "P", "o" (keeping the compound inner shape intact) and "t".

Bear in mind:

  • this method is not perfect and can only group overlapping shapes – a shape like "i" will be separated to the vertical stem and the dot
  • when aiming at the most compact SVG output , you should prefer the concatenated output as it significantly reduces the document overhead

SVG Path optimizations

Will remove colinear commands and reduce file-size.
By default Potrace-plus return relative commands and applies shorthands where possible. In case you encounter issues, you can disable it via option:

let traced = await PotracePlus(img, 
    {
        optimize:false,
        toRelative : false,
        toShorthands : false,
        decimals : 3
    }
);

If you need to process the pathdata in a normalized format you can also acces this unoptimized pathdata via the traced.pathDataArr containing all commands in absolute coordinates – split into sub path chunks.

Downgrading

In case you encounter any issues you can try to use the previous version.
See all version on npm.

Analogous you can switch to previous versions for cdn links like so

<script src="https://cdn.jsdelivr.net/npm/potrace-plus@latest/dist/potrace-plus.min.js"></script>

to

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/potrace-plus.min.js"></script>

Demo

Check the webapp to test different settings – or just to vectorize images.