Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hunghg255/dom-to-images

Convert html to image
https://github.com/hunghg255/dom-to-images

dom-to-image html-to-image npm

Last synced: 3 months ago
JSON representation

Convert html to image

Awesome Lists containing this project

README

        



logo


A library convert html to image


NPM Version
NPM Downloads
Minizip
Contributors
License

## Usage

```ts
import { toPng, toJpeg, toBlob } from "dom-to-images"

const dataUrl = await toPng(el, options)
const dataUrl = await toJpeg(el, options)
const blob = await toBlob(el, options)
```

## Options

```ts
export interface Options {
filter?: (node: Node) => boolean
bgcolor?: string
width?: number
height?: number
style?: {}
quality?: number
imagePlaceholder?: string
cacheBust?: boolean
}
```

## Browser Support

```html

DomToImage.toPng(document.body).then(function (dataUrl) {
const a = document.createElement('a')
a.download = 'image.png'
a.href = dataUrl
a.click()
})

```