I've got a problem with getting image dimensions. I want to know the width and height of image without its loading into document. At present I have code as follows:
function getImageSize (path) {
var image = new Image();
image.name = path;
var d = image.onload = function() {
var w = this.width;
var h = this.height;
return {width : w, height : h};
}();
image.src = path;
return d;
}
If I call that function, I get object containing undefined in both index (w, h). I've tried not call onload handler by exclude parenthesis (8 line) but what I get is function code.
Note that if I call alert(w)
inside onload handler body, I can see width of picture but outside it not.
Does someone know how to solve that problem? How can I get image dimension?