Home > Article > Web Front-end > How to save a DIV as an image with extension using HTML5 canvas?
#DIV content can be saved as an image with the help of the html2canvas() function in JavaScript. The DIV tag defines a section in an HTML document.
<div id = ”cpimg” style = ”padding: 25px ; ” > <h4>Welcome</h4> </div>
This shows a divided region named cpimg.
html2canvas() function uses the following code to save a div as an image -
html2canvas(document.querySelector(“#cpimg”)).then(canvas { document.body.appendChild(canvas) });
It saves the referenced div part "cpimg" into an image.
The above is the detailed content of How to save a DIV as an image with extension using HTML5 canvas?. For more information, please follow other related articles on the PHP Chinese website!