[removed] Get image dimensions

后端 未结 8 1799
攒了一身酷
攒了一身酷 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 19:46

    This uses the function and waits for it to complete.

    http://jsfiddle.net/SN2t6/118/

    function getMeta(url){
        var r = $.Deferred();
    
      $('').attr('src', url).load(function(){
         var s = {w:this.width, h:this.height};
         r.resolve(s)
      });
      return r;
    }
    
    getMeta("http://www.google.hr/images/srpr/logo3w.png").done(function(test){
        alert(test.w + ' ' + test.h);
    });
    

提交回复
热议问题