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

html-to-image

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-to-image

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

  • 1.8.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
369K
decreased by-26.09%
Maintainers
1
Weekly downloads
 
Created

What is html-to-image?

The html-to-image npm package allows you to convert HTML nodes to various image formats such as PNG, JPEG, and SVG. It is useful for generating images from web content dynamically.

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

Convert HTML to PNG

This feature allows you to convert an HTML node to a PNG image. The code sample demonstrates how to select an HTML element by its ID and convert it to a PNG image, which is then appended to the document body.

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

Convert HTML to JPEG

This feature allows you to convert an HTML node to a JPEG image. The code sample demonstrates how to select an HTML element by its ID and convert it to a JPEG image with a specified quality, which is then downloaded.

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

Convert HTML to SVG

This feature allows you to convert an HTML node to an SVG image. The code sample demonstrates how to select an HTML element by its ID and convert it to an SVG image, which is then appended to the document body.

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

Other packages similar to html-to-image

Keywords

FAQs

Package last updated on 15 Sep 2021

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