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.

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

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