I'm trying to get image dimensions. here is my attempt with .load
function checkgallery_imagesize(src) {
var dimensions = [];
$("<img/>").load(function(){
dimensions.push(this.width);
dimensions.push(this.height);
}).attr("src", src);
return dimensions;
}
var src = 'example.png';
dimensions = checkgallery_imagesize(src);
console.log(dimensions[0]); //width;
console.log(dimensions[1]); //height;
When i use console.log(dimensions)
. I see the dimensions in the array but i can't access the array. dimensions[0]
and dimensions[1]
are both undefined