I am using the following snip of Javascript from another SO answer:
var _URL = window.URL || window.webkitURL;
$("#file").change(function (e) {
var file, img;
if ((file = this.files[0])) {
img = new Image();
img.onload = function () {
alert(this.width + " " + this.height);
};
img.src = _URL.createObjectURL(file);
}
});
I cannot figure out how to get access to those this.width and this.height variables outside of the function. I have set them equal to existing variables and the variables are always 0 or null.
onloadhandler and I'm pretty sure you need to add the image to the DOM for it to load.global variableand assignthis.widthandthis.heightin that. :Pthisrefers to the image object being loaded. theonloadfunction is executed asynchronously._URL.createObjectURL(file)line and just created the src with a string representing the URL, and I was able to get the width and height onload. This makes me think there's something wrong with_URL.createObjectURL(file);jsfiddle.net/gzm2xghL