Get the image width and height of an image file at a remote URL in Javascript

Here’s how you can get the image width and height of an image file at a remote URL.

function getImgDims(url){
   var img = new Image();
   img.onload = function(){
      var rtnArr=Array;
      
      rtnArr['width']=this.width;
      rtnArr['height']=this.height;
      
      return rtnArr;
   };
   
}

This will return an a multi-element associative array containing values under “width” and “height” as its keys.

Leave a Reply 0

Your email address will not be published. Required fields are marked *