js 图片等比压缩

 传入宽高 等比压缩图片

function proDownImage(width,height,size) {
        var proMaxHeight=350; 
        var proMaxWidth = 400; 
        var ww = proMaxWidth / width; 
        var hh = proMaxHeight /height;  
        var rate = (ww < hh) ? ww: hh; 
        if (rate <= 1) {  
            size.width = width * rate; 
            size.height = height * rate; 
        } else {   
            size.width =width;   
            size.height =height;    
        } 
        return size;    
    } 

                    function(e) {
                        var size = new Object();
                        size=proDownImage(Wflag,Hflag,size);

                      //可如此得到压缩后的宽高

                      size.height  size.width.
                    

你可能感兴趣的:(jquery,宽高等比压缩)