Answer the question
In order to leave comments, you need to log in
Is it possible to load the image that we display in the canvas according to the old dimensions?
I load an image (size 1200x1200) into a 400x400 canvas. Is it possible to download a picture from a canvas with a size of 1200-1200, otherwise it is downloaded with a size of 400x400 through canvas.toDataURL
$(document).on('click', '#download-btn', function () {
var actualName = 'test';
var canvas = document.getElementById('canvas-image-edit');
download(canvas, actualName + '-edited.jpg');
});
function download(canvas, filename) {
var e;
var lnk = document.createElement('a');
lnk.download = filename;
lnk.href = canvas.toDataURL("image/jpeg", 0.8);
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");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question