Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-to-image

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-to-image

Generates an image from a DOM node using HTML5 canvas and SVG

  • 2.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
198K
increased by6.92%
Maintainers
1
Weekly downloads
 
Created

What is dom-to-image?

The dom-to-image npm package allows you to convert DOM nodes into images. It supports various output formats such as PNG, JPEG, and SVG. This can be useful for creating screenshots, generating thumbnails, or exporting visual content from web applications.

What are dom-to-image's main functionalities?

Convert DOM to PNG

This feature allows you to convert a DOM node to a PNG image. The resulting image is appended to the body of the document.

domtoimage.toPng(document.getElementById('my-node')).then(function (dataUrl) {
  var img = new Image();
  img.src = dataUrl;
  document.body.appendChild(img);
}).catch(function (error) {
  console.error('oops, something went wrong!', error);
});

Convert DOM to JPEG

This feature allows you to convert a DOM node to a JPEG image with a specified quality. The resulting image is downloaded as a file.

domtoimage.toJpeg(document.getElementById('my-node'), { quality: 0.95 }).then(function (dataUrl) {
  var link = document.createElement('a');
  link.download = 'my-image-name.jpeg';
  link.href = dataUrl;
  link.click();
}).catch(function (error) {
  console.error('oops, something went wrong!', error);
});

Convert DOM to SVG

This feature allows you to convert a DOM node to an SVG image. The resulting image is appended to the body of the document.

domtoimage.toSvg(document.getElementById('my-node')).then(function (dataUrl) {
  var img = new Image();
  img.src = dataUrl;
  document.body.appendChild(img);
}).catch(function (error) {
  console.error('oops, something went wrong!', error);
});

Convert DOM to Blob

This feature allows you to convert a DOM node to a Blob object. The resulting Blob can be saved as a file using the FileSaver.js library.

domtoimage.toBlob(document.getElementById('my-node')).then(function (blob) {
  window.saveAs(blob, 'my-node.png');
}).catch(function (error) {
  console.error('oops, something went wrong!', error);
});

Other packages similar to dom-to-image

Keywords

FAQs

Package last updated on 04 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc