I would like to create a save image input button that:
- Take a screenshot of the div
- ask "Save As" on the user computer.
I found how to create a dive screen using html2canvas and open it in a new tab, it works fine:
function printDiv2(div) { html2canvas((div), { onrendered: function(canvas) { var img = canvas.toDataURL(); window.open(img); } }); }
But for you, Save as part, it's kind of the hard part ... I found interesting topics, since I'm new to JS (and object) coding, I'm a little confused ... I think I will have to use FileSaver.js and create new blob http://eligrey.com/blog/post/saving-generated-files-on-the-client-side/
But I don’t understand how to implement saveAs in my html2canvas, how to draw a new blob correctly ...
function printDiv2(div) { html2canvas((div), { onrendered: function(canvas) { var img = canvas.toDataURL(); window.open(img); var blob = new Blob(img, {type: "image/jpeg"}); var filesaver = saveAs(blob, "my image.png"); } }); }
I also tried to do something with this by extracting the base64 source URL, but for me it is too hard to understand: http://bl.ocks.org/nolanlawson/0eac306e4dac2114c752
But will someone give me some advice and help me?
Jaggana
source share