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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pixelated-svg

v1.0.1

Published

Create SVG vector image from raster image with keeping pixeleated visual.

Downloads

9

Readme

pixelated-svg

Build Status Coverage Status Dependency Status NPM MIT

Create SVG vector image from raster image with keeping pixeleated visual.

Functions

fromPng

Create SVG document from PNG file. Asynchronous function. Returns Promise. See also Options.

const svg = require('pixelated-svg');
svg.fromPng('foobar.png').then(svg => {
    console.log(svg);
    // <?xml version="1.0"?><!DOCTYPE svg ...
  });

NOTE: This package is targeting small raster images (like classic game resources). If very huge and colorful images is specified, it might take a long computing time or raise memory insufficient error.

Options

Some options are prepared for fromPng.

scale

By default, scale is 1, so output SVG size equals with source raster image size. For example, if source image has 8 pixel width, SVG width becomes 8.

Specify scaling factor by scale option to change SVG size.

svg.fromPng('8x8.png', {
  scale: 100,
}).then(...); // becomes 800 x 800 SVG

includeColors, excludeColors

Specify RGBA colors to include or exclude.

The following example picks only RED and CYAN to generate SVG. All other colors to be treated as transparent and no path drawn.

const RED  = [171,  70,  66, 255];
const CYAN = [124, 175, 194, 255];
svg.fromPng('colorful.png', {
  includeColors: [ RED, CYAN ],
}).then(...);

excludeColors works as reverse option of includeColors, so if change includeColors of the above example to excludeColors, only RED and CYAN colors goes transparent and all other colors are included.

If both includeColors and excludeColors are specified, only colors satisfying both conditions are selected. Therefore, only CYAN will be selected on the following example.

svg.fromPng('colorful.png', {
  includeColors: [ RED, CYAN ],
  excludeColors: [ RED, ]
}).then(...);

Finally, special selector syntax are avaiable for both includeColors and execludeColors:

  • Wildcard (*)
  • Equality (==)
  • Inequalities (!=, <=, <, >=, >)

For example,

const selector = ['< 249', '>= 35', 156, '*'];
svg.fromPng('rgb.png', {
  includeColors: [ selector ],
}).then(...);

This can select colors that satisfy the next conditions:

  • R < 249
  • B >= 35
  • G == 156
  • A can be any value

CLI

Command line interface will be available when globally installed. (npm install -g pixelated-svg)

pixelated-svg raster.png --scale 100 > out.svg

Command line options correspond with fromPng options:

  • --scale or -s
    • Corresponds with scale.
  • --include, -i, --exclude, -e (Experimental)
    • Correspond with includeColors and excludeColors options
    • Syntax must be "exact" JSON Array format. (eg. -i "[[171, 70, 66, 255]]").
      • This inconvenient constraint will be change later.

License

MIT License

(C) 2017 Retorillo