admin管理员组文章数量:1403364
I have an image which is drawn on the canvas. I have a save as html input button in my page. When i click this button it should display a save as dialog and I have to save this image on the disk in jpeg format. How can do this functionality using javascript?
I have an image which is drawn on the canvas. I have a save as html input button in my page. When i click this button it should display a save as dialog and I have to save this image on the disk in jpeg format. How can do this functionality using javascript?
Share Improve this question asked Dec 31, 2012 at 11:25 KiranPalodeKiranPalode 4983 gold badges8 silver badges23 bronze badges 1- stackoverflow./questions/7951326/… – aug Commented Dec 31, 2012 at 11:28
2 Answers
Reset to default 5Use the base64 URI from canvas.toDataURL
as the href
for a link, along with the download
attribute.
It should look something like:
<a href="data:image/png;base64,iVBORw0..." download="my-image">Save Image</a>
use eligrey polyfill to save images to disk.
The W3C File API includes a FileSaver interface, which makes saving generated data as easy as saveAs(data, filename), though unfortunately it will eventually be removed from the spec. a JavaScript library called FileSaver.js
, which implements FileSaver in all modern browsers. Now that it’s possible to generate any type of file you want right in the browser, document editors can have an instant save button that doesn’t rely on an online connection. When paired with the standard HTML5 canvas.toBlob() method, FileSaver.js lets you save canvases instantly and give them filenames, which is very useful for HTML5 image editing webapps.
For browsers that don’t yet support canvas.toBlob(), use canvas-toBlob.js.
article
DEMO
本文标签: javascriptHow can save as image to disk from HTML5 canvasStack Overflow
版权声明:本文标题:javascript - How can save as image to disk from HTML5 canvas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744358932a2602447.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论