What are the different ways to save a canvas object?
In my research, I've found two approaches:
var data = canvas.toDataURL();
var prev = window.location.href;
window.location.href = data.replace("image/png", "image/octet-stream");
window.location.href = prev;
Another way is to take a snapshot.
Are there other ways to do this?
Is it possible to customize the download filename?
This solution is better:
Solution that doesn't require you to create a button.
Useful if you have other triggers for downloading, or triggers that you can't easily reference.
The one way to save is exporting as an image... You already found this solution, and it's the best one i think ;)
You can use different image types. Change the mimetype in this function:
An other way to save canvas data (into a PDF) is using the wkhtmltopdf Library
Cheers. Frank
frankneff.ch / @frankneff
I hope these code would be work. But first create Anchor tag in canvas tag whose id is 'cropImageLink'. than after check. but it's not working in IE browser
You can use the reimg library to do this really easily.
Converting the canvas to an img :
ReImg.fromCanvas(document.getElementById('yourCanvas')).toPng()
And downloading this image for the user can be done like this :
ReImg.fromCanvas(document.getElementById('canvas')).downloadPng()
About giving the file a custom name, if you look into the code of the library (which is very short and simple to understand) you'll find that you can change the name.
Here is a link to the specific line: https://github.com/gillyb/reimg/blob/master/reimg.js#L56