Skip to content

Simple function to create a canvas element from HTML

Notifications You must be signed in to change notification settings

danielrw7/htmlToCanvas.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

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

About

Simple function to create a canvas element from HTML

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published