A simple Node.js library to convert raster images into svg

Overview

@neplex/vectorizer

A simple Node.js library to convert raster images into svg using VTracer, with time complexity of O(n).

Installation

npm install @neplex/vectorizer

Usage

import {
  vectorize,
  ColorMode,
  Hierarchial,
  PathSimplifyMode,
} from '@neplex/vectorizer';
import { readFile, writeFile } from 'node:fs/promises';

const src = await readFile('./raster.png');

const svg = await vectorize(src, {
  colorMode: ColorMode.Color,
  colorPrecision: 6,
  filterSpeckle: 4,
  spliceThreshold: 45,
  cornerThreshold: 60,
  hierarchical: Hierarchical.Stacked,
  mode: PathSimplifyMode.Spline,
  layerDifference: 5,
  lengthThreshold: 5,
  maxIterations: 2,
  pathPrecision: 5,
});

console.log(svg); // <svg>...</svg>
await writeFile('./vector.svg', svg);

If you want to use synchronous API, you can use vectorizeSync instead.

API

vectorize(data: Buffer, config?: Config | Preset): Promise<string>

Takes an image buffer and returns a promise that resolves to an SVG string.

vectorizeSync(data: Buffer, config?: Config | Preset): string

Takes an image buffer and returns an SVG string synchronously.

vectorizeRaw(data: Buffer, args: RawDataConfig, config?: Config | Preset): Promise<string>

Takes a raw pixel data buffer and returns a promise that resolves to an SVG string.

vectorizeRawSync(data: Buffer, args: RawDataConfig, config?: Config | Preset): string

Takes a raw pixel data buffer and returns an SVG string synchronously.

Demo

Generated under the following configuration:

{
    colorMode: ColorMode.Color,
    colorPrecision: 8,
    filterSpeckle: 4,
    spliceThreshold: 45,
    cornerThreshold: 60,
    hierarchical: Hierarchical.Stacked,
    mode: PathSimplifyMode.Spline,
    layerDifference: 6,
    lengthThreshold: 4,
    maxIterations: 2
}
Raster Image (PNG Input) Vector Image (Generated SVG)
Raster Image
CC-BY-SA 3.0 by Niabot
Vector Image
CC-BY-SA 3.0 by Niabot
You might also like...
hj is a command line tool to convert HTTP/1-style text into JSON

hj hj is a command line tool to convert HTTP/1-style text into JSON. This command is inspired by yusukebe/rj, which is a standalone HTTP client that s

A tool to convert old and outdated "characters" into the superior Rustcii-Encoding.

rustcii A tool to convert old and outdated "characters" into the superior Rustcii-Encoding. Speak your mind. Blazingly ( πŸ¦€ ) fast ( πŸš€ ). Github | cr

🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.
🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.

Marky Markdown Magician πŸ§™ Features Hot reload previewing πŸ”₯ Conversion to HTML / PDF 🏭 Themes! ✨ Extensions - Math, diagrams, syntax-highlighting 🧩

ufo2nft is a CLI Rust tool to automate creating on-chain SVG NFTs from UFO font sources

ufo2nft is a CLI Rust program created by Eli Heuer at the 2022 Seattle Solana Hacker House event. It uses Norad to create on-chain SVG images from UFO font sources, and prepares them for minting as Solana NFTs. For Ethereum NFTs the program can just export the SVGs and Ethereum NFTs can be built manually.

Captcha based on SVG.

BioSvg Captcha based on SVG. Original idea SVGη»˜εˆΆεŽŸη†δΈŽιͺŒθ―η  Usage cargo add biosvg let (answer, svg) = BiosvgBuilder::new() .length(4) .difficulty(

An mdBook backend to output Typst markup, pdf, png, or svg

mdbook-typst mdbook-typst is a backend for mdBook. The backend converts the book to Typst markup and can output any format Typst can (currently pdf, p

SVG to PDF file conversion based on "svg2pdf" and "resvg" Rust projects

pysvg2pdf Blazingly Fast ℒ️ SVG to PDF file conversion for Python. This project is based on Rust's svg2pdf and resvg projects. The project uses pyo3 a

A simple CLI utility to add rounded borders, padding, and shadows to images.

shadower a simple command-line utility to add rounded corners and shadows to images Installation From AUR paru -S shadower-git From source cargo build

This is a simple command line application to convert bibtex to json written in Rust and Python

bibtex-to-json This is a simple command line application to convert bibtex to json written in Rust and Python. Why? To enable you to convert very big

Releases(v0.0.4)
Owner
Neplex
Neplex open source community
Neplex
PlandUML and Drawio diagrams in doc comments as PNG or SVG images.

rsdoc This crate provides a procedural macro that transform PlandUML and Drawio diagrams in doc comments as PNG or SVG images. The diagrams in doc com

null 4 Feb 20, 2023
A simple CLI tool to convert the images to ASCII art with rust πŸ¦€πŸ’™

aarty: A simple CLI tool to convert images to ASCII art with Rust ?? More screenshots Original image Original image Original image Original image Orig

Anas Elgarhy 26 Feb 13, 2023
Turns lines of text into SVG files.

Sentences 2 svg Does what it says on the tin. This takes in a file with some sentences and outputs numbered svgs. There are 3 arguments to keep in min

Fallen 4 Eyes 1 Jan 1, 2022
convert images to ansi or irc, with a bunch of post-processing filters

img2irc (0.2.0) img2irc is a utility which converts images to halfblock irc/ansi art, with a lot of post-processing filters halfblock means that each

null 6 Apr 4, 2023
Convert your favorite images and wallpapers with your favorite color palettes/themes

dipc doprz' image palette converter Convert your favorite images and wallpapers with your favorite color palettes/themes Color Palettes/Themes catppuc

null 50 Apr 26, 2023
A simple (but really fast!) CLI tool to convert an epub into a text file.

epub_to_txt A simple (but really fast!) CLI tool written in Rust to convert an epub into a text file (in Markdown format). Usage epub_to_txt filename.

Darren Mothersele 3 Jul 30, 2023
Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and at compile-time.

rgb2ansi256 rgb2ansi256 is a small Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and const fn. Th

Linda_pp 7 Nov 17, 2022
A series of crates that I made to compile images/video into asciinema & play them.

Bad Apple A series of crates that I made to compile images/video into asciinema & play them. The end goal is to make a kernel & legacy bootloader that

S0ra 10 Nov 29, 2022
Nvm - Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager Table of Contents Intro About Installing and Updating Install & Update Script Additional Notes Troubleshooting on Linux Troublesh

nvm.sh 63.8k Jan 7, 2023
Abuse the node.js inspector mechanism in order to force any node.js/electron/v8 based process to execute arbitrary javascript code.

jscythe abuses the node.js inspector mechanism in order to force any node.js/electron/v8 based process to execute arbitrary javascript code, even if t

Simone Margaritelli 301 Jan 4, 2023