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

deca-svgify

v1.0.1

Published

Convert image data to scalable vector graphics (SVG)

Downloads

6

Readme

Deca SVGify

A TypeScript-based NPM package that converts image data (such as canvas, PNG, or JPEG) into scalable vector graphics (SVG).

Installation

npm install deca-svgify

Usage

import { imageToSvg } from 'deca-svgify';

const canvas = document.getElementById('myCanvas') as HTMLCanvasElement;
const ctx = canvas.getContext('2d')!;
ctx.fillRect(0, 0, 100, 100);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);

const svgElement = imageToSvg(imageData, {
  backgroundColor: '#f0f0f0',
  viewBox: '0 0 100 100',
  style: {
    border: '1px solid #ccc'
  }
});

document.body.appendChild(svgElement);

API

imageToSvg(imageData: ImageData, options?: SVGOptions)

Converts the provided ImageData object to an SVGElement.

Parameters

  • imageData (ImageData): An object containing the image data, including width, height, and pixel data.
  • options (SVGOptions, optional): An object with the following optional properties:
    • backgroundColor: A CSS color value to set as the SVG background.
    • viewBox: A string representing the viewBox attribute of the SVG element.
    • style: An object of CSS styles to apply to the SVG element.

Returns

An SVGElement representing the converted image.

Motivation

Vectorizing images, or converting them to the SVG format, allows you to scale the graphics without losing quality. This is particularly useful for elements like logos, icons, or illustrations that need to be displayed at different sizes in your web application.

Benefits

  • Scalable Graphics: SVG images are resolution-independent, meaning they can be scaled up or down without losing quality.
  • Customizable Appearance: The SVG output can be easily customized with styles, background colors, and other properties.
  • Lightweight and Efficient: SVG files are generally smaller in size than raster image formats like PNG or JPEG, improving load times and performance.
  • Accessibility: SVG images are easily accessible and can be manipulated with CSS and JavaScript.

Example Use Cases

  • Web Applications: Use this library to convert canvas, PNG, or JPEG images to SVG for use in your web application's UI.
  • Icon Libraries: Generate SVG icons from raster image sources and distribute them as a reusable library.
  • Data Visualization: Convert chart or graph data into SVG for scalable, resolution-independent visualization.
  • Logo Design: Create SVG logos that can be easily resized and integrated into your branding.

Contributing

If you find any issues or have suggestions for improvements, please feel free to open a GitHub issue or submit a pull request.

License

This project is licensed under the MIT License.