sunlanda
9/1/2016 - 9:54 AM

获取图片宽高

获取图片宽高

 getImageSize: function(url,callback){
            var img = new Image();
            img.src = url;
                // 如果图片被缓存,则直接返回缓存数据
            if(img.complete){
                callback(img.width, img.height);
            }else{
                // 完全加载完毕的事件
                img.onload = function(){
                    callback(img.width, img.height);
                }
            }

        },
//调用
 var imgSrc = $("#imgHidden").attr("src");
                           evt.getImageSize(imgSrc,function(w,h){
                               console.log(w,h);
                           });


//其他办法
// Get on screen image
var screenImage = $("#image");

// Create new offscreen image to test
var theImage = new Image();
theImage.src = screenImage.attr("src");

// Get accurate measurements from that.
var imageWidth = theImage.width;
var imageHeight = theImage.height;