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,983stars
Mozilla Public License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
52/100Fair
Development Activity24
Maintenance44
Community44
Maturity56
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture78
Code Quality82
Innovation74
Learning Curve55

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 8 apps in this directory

Rust
67%
MIT

Bun

Developer Tools

95,895

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
Rust67%
C++19%
Updated yesterday
TypeScript
93%
MIT

bunqueue

Developer Tools · Devops

558

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

View details
75
Repo Health
83
Technical
75
Dependency
Built with
TypeScript93%
Updated 2 days ago
TypeScript
82%
MIT

evidence

Analytics · Data Engineering

6,911

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
87
Repo Health
79
Technical
64
Dependency
Built with
TypeScript82%
Svelte18%
Updated 3 days ago
TypeScript
98%
Other

Hexabot

AI Development · Automation

1,213

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

View details
77
Repo Health
76
Technical
65
Dependency
Built with
TypeScript98%
Updated 2 weeks ago
TypeScript
79%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,630

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
TypeScript79%
Python11%
Updated yesterday
TypeScript
80%
Apache 2.0

nao

AI Development · Analytics

1,611

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
TypeScript80%
Python19%
Updated yesterday
HTML
36%

OpenPanel

Hosting Control Panel · Devops

743

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
81
Repo Health
75
Technical
63
Dependency
Built with
HTML36%
Go32%
TypeScript25%
Updated yesterday
TypeScript
100%
MIT

Rudel

Developer Tools

290

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
71
Dependency
Built with
TypeScript100%
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

Search