Home  >  Article  >  Web Front-end  >  js realizes saving the image generated by canvas or directly saving a picture

js realizes saving the image generated by canvas or directly saving a picture

小云云
小云云Original
2018-05-19 15:49:133142browse

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.

Save the canvas array

<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

Method to directly save the picture

<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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn