Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 599 Bytes

README.md

File metadata and controls

30 lines (26 loc) · 599 Bytes

htmlToCanvas.js

Simple function to create a canvas element from HTML

Example

htmlToCanvas(`
    <div xmlns="http://www.w3.org/1999/xhtml">
        <em>I</em>
        am 
        <span style="color:blue;">
            HTML
        </span>
    </div>
`, `
    <style>
        foreignObject div {
            font-size: 40px;
            color: red;
        }
    </style>
`, 200, 50).then(canvas => {
    const $img = document.createElement('img')
    $img.src = canvas.toDataURL('image/png')
    document.body.appendChild($img)
})

example.png