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,776stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
43/100Fair
Development Activity0
Maintenance0
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
62/100Good
Architecture62
Code Quality55
Innovation60
Learning Curve70

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

Low Code Platforms · Databases

15,526

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

View details
53
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated 9 months ago
TypeScript
98%
MIT

isoflow

Design Tools · Developer Tools

1,688

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
TypeScript98%
Updated 11 months ago
JavaScript
44%
Other

LimeSurvey

Forms Surveys

3,698

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
62
Dependency
Built with
JavaScript44%
PHP34%
CSS12%
Updated today
TypeScript
76%
AGPL 3.0

massCode

Developer Tools · Productivity · Code Editors

6,959

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

View details
86
Repo Health
87
Technical
64
Dependency
Built with
TypeScript76%
Vue22%
Updated 2 days ago
Python
67%
Apache 2.0

Polar

Ecommerce · Developer Tools · Invoicing Finance

10,199

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
71
Dependency
Built with
Python67%
TypeScript26%
Updated today

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