# dom2pic

> transfer a html dom to canvas/png/jpeg/svg element/multiple pictures

Latest version **1.0.9** (published 2020-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install dom2pic
pnpm add dom2pic
yarn add dom2pic
bun add dom2pic
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2020-11-18 |
| First published | 2020-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 34.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | korbinzhao |
| Maintainers | korbinzhao |
| Keywords | dom2pic, dom2img, dom2image, html2img, html2image, html2pic, domtoimg, domtoimage, domtopic, htmltoimg, htmltoimage, htmltopic |

## Links

- npm: https://www.npmjs.com/package/dom2pic
- Repository: https://github.com/korbinzhao/dom2pic
- Issues: https://github.com/korbinzhao/dom2pic/issues
- npm.io page: https://npm.io/package/dom2pic

## Dependencies (1)

- [core-js](https://npm.io/package/core-js.md) 3.6.5

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.9 (latest) — 2020-11-18
- 1.0.8 — 2020-05-14
- 1.0.7 — 2020-05-14
- 1.0.6 — 2020-05-14
- 1.0.5 — 2020-05-13
- 1.0.4 — 2020-05-13
- 1.0.3 — 2020-05-12
- 1.0.2 — 2020-05-11
- 1.0.1 — 2020-05-07
- 1.0.0 — 2020-04-26

## README

# dom2pic
transfer a html dom to canvas/png/jpeg/svg element/multiple pictures

# usage

```
const Dom2pic = require('dom2pic');

const dom2pic = new Dom2pic({
  root: document.querySelector('.content2screenshot'),
  backgroundColor: '#e2e2e2'
});

dom2pic.toPng()
  .then(base64 => {

    console.log('--- png base64 ---', base64);

  });

dom2pic.toJpeg()
  .then(base64 => {

    console.log('--- jpeg base64 ---', base64);

  });

dom2pic.toSvg().then(svg => {
  document.body.appendChild(svg);
});


dom2pic.toCanvas()
  .then(canvas => {

    console.log('--- canvas ---', canvas);

  });


dom2pic2.toMultiPictures('.item', 'jpeg').then(results => {
  console.log('--- results ---', results);

  results.forEach(obj => {
    const img = document.createElement('img');
    img.src = obj.uri;
    img.style.width = '200px';
    document.body.appendChild(img);
  })
})

```

# API 
* new Dom2pic(config)
  * new a Dom2pic instance
  * options
    * root
      HTMLElement | string; // root html dom to screenshot, cannot be absolute position
    * backgroundColor 
      string; // optional, set root dom backgroundColor
* toCanvas
  * generate a canvas from a dom element
* toPng
  * generate a png base64 string from a dom element
* toJpeg
  * generate a jpeg base64 string from a dom element
* toSvg
  * generate a svg from a dom element
* toMultiPictures
  * generate multiple pictures according to child dom className
  * options
    * childNodeSelector 
      string; generate multiple pictures by childNodeSelector
    * type 
      png | jpeg

# demo && development
```
npm install

npm start
```

---
_Source: https://npm.io/package/dom2pic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
