[removed] Get image dimensions

后端 未结 8 1813
攒了一身酷
攒了一身酷 2020-11-29 19:11

I only have a URL to an image. I need to determine the height and width of this image using only JavaScript. The image cannot be visible to the user on the page. How can I g

8条回答
  •  长情又很酷
    2020-11-29 20:01

    var img = new Image();
    
    img.onload = function(){
      var height = img.height;
      var width = img.width;
    
      // code here to use the dimensions
    }
    
    img.src = url;
    

提交回复
热议问题