i try to get image width and height returned from a function, but every time it get's returned as undefined, if i console.log values in the function it shows up, but it returns undefined every time.
The main problem i suspect is with scope, because it is a nested function, but i am not really sure, if thats the case.
JS code
//get image width and height
$(document).ready(function(){
//object method
function dimensions($width, $height){
this.getWidth = $width;
this.getHeight = $height;
}
//gets image data
function readURL(input) {
var reader = new FileReader();
var image = new Image();
reader.onload = function (e) {
image.src = e.target.result;
}
reader.readAsDataURL(input.files[0]);
return image;
}
//gets image dimensions (width height)
function getImageDimensions($img){
var $dimensions;
$img.onload = function(){
$dimensions = new dimensions($img.width, $img.height);
}
return $dimensions;
}
$("#imgInp").change(function(){
alert(getImageDimensions(readURL(this)));
});
});
Html code
<form id="form1" runat="server">
<input type='file' id="imgInp" accept="image/*"/>
</form>
Can anyone explain to me why it doesn't return a object, but returns undefined?