So Im trying to build an app using electron, the program is pretty basic, the user should upload a couple of pictures, they press a button, I draw them into a <canvas>
element and they should be able to download it, the problem that Im having is that when I try to make a downloadable button, a security error is thrown, I did some research and find out that it's a feature of HTML5, the think is that i can't add the crossOrigin = 'Anonymous' because the user is going to load the picture from its own computer, so my question is...
a)- is there a way to "cheat the system" and be able to download the content of the canvas?,
b)- if (a) is not posible...is there an alternative that could work similary to a canvas element?
I'm already using FileReader() to get the picture the user selected, and i'm already drawing that into the canvas, and it looks great, the problem that I have is that i can't download the content that I created for that security error. the .toDataURL can't be called because that's the one that throws the error.
The code to read the pictures from the inputs:
function handleBox1(evt) {
var files = evt.target.files; // FileList object
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
$('#imgBox1').attr("src",e.target.result);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
this is a simple function to see if I could get the Url from the canvas:
descargar = function(){
var w=window.open('about:blank','image from canvas');
w.document.write("<img src='"+ totem.toDataURL("image/png")+ "' alt='from canvas'/>");
}