I'm trying to make a save function for a photo editing app I am making and I am stumped on what to set the variable to. The line that is the issue is let imageData = image.toDataURL("image/jpg");
I have tried setting the variable to a few different things but none of them seem to work. Any thoughts?
// Get the source image to be edited
let image = document.getElementById('sourceImage');
function uploadImage(event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(e) {
image.src = reader.result;
};
reader.readAsDataURL(file)
}
// Save the edited image
function saveImage() {
let linkElement = document.getElementById('link');
linkElement.setAttribute('download', 'edited.jpg');
let imageData = image.toDataURL("image/jpg");
imageData.replace("image/jpg", "image/octet-stream");
linkElement.setAttribute('href', imageData);
linkElement.click();
}
Just as a note, I have an applyFilter() function but it didn't seem relevant to put in here, if needed I can add it