I have been trying to return an image blob object from within these nested functions. You can see in my code that I tried the idea given in this answer, but did not help. Please read all the comments in the code to grasp the scenario. Please let me know if need more details.
function resizetoBlob(file) { //resizes given image file to blob
var blob = "";
var reader = new FileReader();
reader.onload = function() {
var tempImg = new Image();
tempImg.src = reader.result;
tempImg.onload = function() {
//resize calculation done here
var dUrl = canvas.toDataURL('image/jpeg',0.8);
blob = dataURLtoBlob(dUrl);
//this is the blob object I need to return
}
}
reader.readAsDataURL(file);
return blob; //obviously this does not work.
}
Here is a link to the function dataURLtoBlob.