resvg-js

A high-performance SVG-to-PNG renderer for Node.js and browsers, powered by Rust's resvg engine via napi-rs and WebAssembly.

Library
npm
v2.6.2
1,994 stars
Mozilla Public License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
50 /100 Fair
Development Activity 16
Maintenance 44
Community 44
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
72 /100 Good
Architecture 78
Code Quality 82
Innovation 74
Learning Curve 55

resvg-js is a Node.js and WebAssembly binding for resvg, a Rust SVG rendering library, that converts SVG documents into PNG raster images. It ships as prebuilt native addons for a wide matrix of platforms via napi-rs, so installing it requires no compiler toolchain, node-gyp, or postinstall build step.

Beyond basic rasterization, it exposes bounding-box calculation and crop-to-content APIs, custom font loading from files or in-memory buffers, deferred resolution of external <image> references, and cancellable async rendering. Its rendering core is shared with a separate WebAssembly build that runs the identical engine directly in browsers, making it one of the few SVG renderers usable identically on the server and client.

What You Get

  • Native Node.js bindings prebuilt for a dozen platform/arch targets (Linux gnu/musl, macOS x64/arm64, Windows x64/ia32/arm64, Android) with no node-gyp or postinstall step
  • A Resvg class that parses an SVG once and can be rendered, measured, and cropped repeatedly without re-parsing
  • Bounding-box APIs (getBBox, innerBBox) and cropByBBox for cropping output to visible content, with optional padding and square cropping
  • A separate WebAssembly build (@resvg/resvg-wasm) that runs the same Rust renderer directly in browsers
  • Custom font loading via files, directories, or in-memory buffers, plus an optional system-fonts fallback
  • Async rendering (renderAsync) with AbortSignal support for cancelling long-running conversions

Common Use Cases

  • Generating Open Graph / social preview images at build time or in serverless functions
  • Converting icon or illustration SVGs to PNG for platforms that don’t support SVG
  • Server-side chart/diagram rasterization for PDF or email generation pipelines
  • Rendering user-uploaded or dynamically generated SVGs to raster images in a browser via the Wasm build
  • Cropping generated PNGs to their visible bounding box before further image processing

Under The Hood

Architecture The Rust core (src/lib.rs, options.rs, fonts.rs, error.rs) compiles to two distinct targets from one codebase via cfg gating: a native N-API addon (napi-rs) for Node.js and a WebAssembly module (wasm-bindgen) for browsers. The Resvg struct wraps a parsed usvg::Tree plus JsOptions, with core operations (render_inner, node_bbox, crop_by_bbox_inner) implemented once in shared inherent impls and exposed through thin, target-specific #[napi]/#[wasm_bindgen] impl blocks. Panic safety is handled explicitly: render_inner_catch_unwind wraps rendering in catch_unwind to convert Rust panics into catchable JS errors instead of crashing the process, and NAPI’s ObjectFinalize/adjust_external_memory hooks report Pixmap buffer sizes to V8 so the GC can reclaim memory more aggressively. The layout is a single-module Rust crate, layered by compile target rather than by directory, so a change to the shared rendering path propagates identically to both the Node and Wasm builds.

Tech Stack A Rust (2024 edition) core built with napi-rs v3, cross-compiled via the napi CLI to a dozen platform targets, alongside a separate wasm-bindgen 0.2 / wasm-pack build for WebAssembly. Rendering is delegated to a patched fork of resvg/usvg (pinned in [patch.crates-io]) plus pathfinder_geometry/pathfinder_content for bounding-box and stroke geometry, the png crate for encoding, a patched woff2 fork for font decompression, and mimalloc as the global allocator on non-Linux/non-wasm targets. JS-side tooling is TypeScript with Yarn 4 (Berry), ESLint (typescript-eslint + sonarjs + import plugins), Prettier, the ava test runner, and a benny-based benchmark suite comparing against sharp and svg2img.

Code Quality Around 1,800 lines of TypeScript tests span four spec files (index.spec.ts, index-bbox.spec.ts, index-panic.spec.ts, wasm.spec.ts) run via ava, covering rendering correctness via pixel comparison against jimp, bounding-box math, deliberately panic-inducing malformed SVG paths, and parity between the native and Wasm builds. A dedicated error.rs translates internal errors into typed NapiError/js_sys::Error, and rendering is wrapped in catch_unwind to turn Rust panics into recoverable JS exceptions. Naming stays consistent across the FFI boundary via explicit #[napi(js_name = ...)]/#[wasm_bindgen(js_name = ...)] annotations mapping snake_case Rust to camelCase JS. CI builds and tests across roughly a dozen target/host combinations; ESLint/typescript-eslint/sonarjs and cargo fmt enforce style on each side. Core Rust logic such as node_bbox and crop_by_bbox_inner has no dedicated Rust-level unit tests, relying instead on JS integration tests against the compiled binary.

What Makes It Unique resvg-js’s differentiator over pure-JS SVG rasterizers or bindings to librsvg/Cairo is shipping resvg, a from-scratch, spec-conformant Rust SVG renderer, as prebuilt native addons across a wide platform matrix with zero postinstall or node-gyp step, and building the identical Rust source a second time as WebAssembly so the same rendering engine runs client-side. Its API surface goes beyond simple SVG-in/PNG-out conversion with element-aware cropping (getBBox/innerBBox/cropByBBox) and deferred external-image resolution (imagesToResolve/resolveImage) for callers that want to fetch referenced images themselves.

Used by 9 apps in this directory

Rust
67%
MIT

Bun

Developer Tools

96,068

An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust 67%
C++ 19%
TypeScript 10%
Updated 5 days ago
TypeScript
93%
MIT

bunqueue

Developer Tools · Devops

570

High-performance job queue for Bun — SQLite persistence, cron scheduling, DLQ, S3 backups, and a native MCP server, all without Redis.

View details
73
Repo Health
83
Technical
72
Dependency
Built with
TypeScript 93%
Updated 3 weeks ago
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

6,962

Turn SQL queries and markdown files into polished, interactive data apps and business intelligence reports — no drag-and-drop, no GUI, just code.

View details
90
Repo Health
79
Technical
64
Dependency
Built with
TypeScript 82%
Svelte 17%
Updated 1 weeks ago
TypeScript
98%
Other

Hexabot

AI Development · Automation

1,260

Build and run agentic workflows across channels with YAML, tools, and RAG

View details
78
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
78%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,686

Open-source AI agent monitoring that catches what will break next before your users do.

View details
86
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 78%
Rust 11%
Python 11%
Updated 1 weeks ago
TypeScript
56%
Apache 2.0

LTX-Desktop

AI Design Tools · Video Editors

2,028

An open-source Electron app that runs LTX-2 text-to-video, image-to-video, and video editing models locally on your GPU, or via a cloud API when your hardware can't keep up.

View details
72
Repo Health
82
Technical
73
Dependency
Built with
TypeScript 56%
Python 41%
Updated 1 months ago
TypeScript
83%
Apache 2.0

nao

AI Development · Analytics

1,702

Build and deploy an open-source analytics agent that understands your data warehouse and answers business questions in plain English.

View details
84
Repo Health
76
Technical
67
Dependency
Built with
TypeScript 83%
Python 17%
Updated 6 days ago
HTML
36%

OpenPanel

Devops · Hosting Control Panel

749

Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.

View details
84
Repo Health
75
Technical
63
Dependency
Built with
HTML 36%
Go 32%
TypeScript 23%
Updated 5 days ago
TypeScript
97%
MIT

Rudel

Developer Tools

303

Open-source analytics for Claude Code and Codex sessions — a CLI uploads session transcripts to a self-hostable dashboard tracking token usage, session duration, activity patterns, and model usage.

View details
75
Repo Health
67
Technical
72
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers