I'd like to set the width of an external image (from another url) into a variable, so I can use the newly assigned variable on another function.
The problem is that I get undefined
message on the variable, see the code below.
var site_url = 'http://fabricjs.com/assets/1.svg';
function getMeta(url, callback) {
var img = new Image();
img.src = url;
img.onload = function() { callback(this.width, this.height); }
}
var a = getMeta(site_url, function(width, height) {
return width;
});
alert(a); //undefined
What am I doing wrong, how should I proceed ?