I have a function to get image dimensions. I send in the return from createObjectURL.
It works fine in getting the dimensions, but I can't get the values back. I am trying to get both values but the issue seems to be that there is a function within the function. And the outer function doesn't know the values that are set in the inner function. When I hard code a value, as in the "qq" below it is fine. So I can see the issues isnt in the return but in the values.
How do you read the values in this situation?
imgSrc = window.URL.createObjectURL(this.files[0]);
var imgSize = getImgSize(imgSrc);
var newWidth = imgSize.retWidth;
var newHeight = imgSize.retHeight;
alert(newWidth);
alert(newHeight);
function getImgSize(imgSrc) {
var newImg = new Image();
newImg.onload = function() {
var nHeight = newImg.height;
var nWidth = newImg.width;
//alert('The image size is ' + width + '*' + height);
}
newImg.src = imgSrc; //this must be done AFTER setting onload
return {
retWidth: nWidth,
retHeight: 'qq'
};
}