I am building a web application when the user can edit an image by using the CSS provided filters and then save it later. In order to save that filtered image i have to draw the image into a canvas and apply the used filters on that image on the canvas itself.
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
canvas.style.filter = "brightness(100%) saturate(200%) contrast(130%)";
context.drawImage(im,0,0);
The whole previous instructions works perfectly fine and i had to display the canvas to make sure that the filters are applied, and they were applied as they suppose. My problem is when i download the image using the following code it only download the image without any edition of the filters.
download(canvas, 'my-image.jpg');
function download(canvas, filename) {
var lnk = document.createElement('a'), e;
lnk.download = filename;
lnk.href = canvas.toDataURL("data:image/jpg;base64");
if (document.createEvent) {
e = document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);
lnk.dispatchEvent(e);
} else if (lnk.fireEvent) {
lnk.fireEvent("onclick");
}
}
Any suggestions to solve this problem?
PS: i'm on macOS and the development runs on Safari 11.1, using python and Flask as well.
I tried the context.filter = "brightness(100%) saturate(200%) contrast(130%)";
and it worked fine in Chrome but not in Safari.