Home > Article > Web Front-end > js realizes saving the image generated by canvas or directly saving a picture
This article mainly shares with you how to use js to save a picture generated by canvas or directly save a picture. I hope it can help you.
<span style="font-size: 14px;">function downLoadImage(canvas,name) {<br/> var a = document.createElement("a");<br/> a.href = canvas.toDataURL();<br/> a.download = name;<br/> a.click();}<br/></span>
canvas: the dom object passed into the canvas
name: the name of the saved image
<span style="font-size: 14px;">function downLoadImage(img,name) {<br/> var a = document.createElement("a");<br/> a.href = img.src;<br/> a.download = name;<br/> a.click();}<br/></span>
img: DOM object of the picture
name: The name when saving as a picture
The above is the detailed content of js realizes saving the image generated by canvas or directly saving a picture. For more information, please follow other related articles on the PHP Chinese website!