dom-to-image

Turn any DOM node into a PNG, JPEG, or SVG image using pure client-side JavaScript

Library
npm
v2.6.0
10,779 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
43 /100 Fair
Development Activity 0
Maintenance 0
Community 72
Maturity 60
Momentum 40

Technical Analysis

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

dom-to-image is a browser library that converts an arbitrary DOM node into a raster (PNG/JPEG) or vector (SVG) image, entirely client-side with no server rendering or screenshot service required. It works by cloning the target node, inlining computed styles, embedding web fonts and images as data URLs, and wrapping the serialized markup in an SVG foreignObject that can be rasterized onto a canvas.

Originally based on Paul Bakaus’s domvas experiment and rewritten from scratch, it has become a long-standing dependency for exporting UI snapshots, charts, and reports directly from the browser without a headless-browser backend.

What You Get

  • toPng/toJpeg/toSvg/toBlob/toPixelData functions returning promises
  • Automatic inlining of web fonts and background/img images as data URLs
  • A node filter callback to exclude specific DOM subtrees from the capture
  • Style overrides (width, height, bgcolor, custom style object) applied before rendering
  • Cache-busting option for fetching fresh copies of remote images

Common Use Cases

  • Exporting a chart, card, or report section as a downloadable image
  • Generating shareable social preview images from rendered UI
  • Producing client-side screenshots for bug reports or PDF export pipelines
  • Snapshotting DOM state in visual regression tooling

Under The Hood

Architecture The library is a single ~770-line file (src/dom-to-image.js) organized as an IIFE exposing toSvg/toPng/toJpeg/toBlob/toPixelData. The core flow clones the target DOM node, walks it recursively via cloneNode/processClone to copy computed styles and pseudo-elements onto each cloned element, resolves and inlines external resources (fonts via fontFaces, images via images module) as base64 data URLs, serializes the result with XMLSerializer, and wraps it in an SVG foreignObject that is either returned directly (toSvg) or drawn onto an offscreen canvas and read back as a PNG/JPEG data URL or Uint8Array pixel buffer.

Tech Stack Zero runtime dependencies — pure browser-standard JavaScript (Promises, DOM, Canvas, SVG). Dev tooling is dated (Grunt, Karma, Bower, JSHint, Mocha/Chai with PhantomJS-era browser launchers), reflecting the library’s 2015-era origins; the package has had no functional releases since 2.6.0 in 2017 despite a 2024 maintenance commit.

Code Quality Tests exist under spec/ (dom-to-image.spec.js) running in Karma against Chrome/Firefox, comparing rendered output pixel-for-pixel via js-imagediff and falling back to OCR (ocrad.js) where pixel comparison is browser-dependent. Code uses consistent module-per-concern internal helpers (fontFaces, images, inliner, util) but has minimal inline documentation and no TypeScript types; error handling is mostly promise rejection with logging left to the caller.

API Design The public surface is small and consistent: five top-level functions all taking (node, options) and returning a promise, with a shared options shape (filter, bgcolor, width/height, style, quality, cacheBust, imagePlaceholder). This makes the library easy to pick up from the README alone, though the impl namespace exposing internals for testing blurs the public/private boundary.

Used by 5 apps in this directory

TypeScript
72%
AGPL 3.0

APITable

Databases · Low Code Platforms

15,623

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
71
Repo Health
77
Technical
60
Dependency
Built with
TypeScript 72%
Java 22%
Updated 3 weeks ago
TypeScript
98%
MIT

isoflow

Design Tools · Developer Tools

1,718

A React component that lets developers embed a fully-featured, isometric network diagram editor directly into their applications.

View details
41
Repo Health
72
Technical
70
Dependency
Built with
TypeScript 98%
Updated 1 years ago
JavaScript
43%
Other

LimeSurvey

Forms Surveys

3,736

The world's most flexible open-source survey platform with 900+ templates, conditional logic, 80+ languages, and full GDPR compliance for any scale.

View details
86
Repo Health
62
Technical
63
Dependency
Built with
JavaScript 43%
PHP 35%
CSS 12%
Updated 6 days ago
TypeScript
80%
AGPL 3.0

massCode

Code Editors · Developer Tools · Productivity

7,003

A free, local-first developer workspace unifying snippets, notes, HTTP requests, calculations, drawings, and dev tools in one desktop app.

View details
87
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 80%
Vue 19%
Updated 6 days ago
Python
65%
Apache 2.0

Polar

Developer Tools · Ecommerce · Invoicing Finance

10,293

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
66
Dependency
Built with
Python 65%
TypeScript 28%
Updated 5 days 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