缩放图片脚本分享
<script> <br><br>function AutoResizeImage(maxWidth,maxHeight){ <br>var objImg = document.getElementById("operImg"); <br>var img = new Image(); <br>img.src = objImg.src; <br>var hRatio; <br>var wRatio; <br>var Ratio = 1; <br>var w = img.width; <br>var h = img.height; <br>wRatio = maxWidth / w; <br>hRatio = maxHeight / h; <br>if (maxWidth ==0 && maxHeight==0){ <br>Ratio = 1; <br>}else if (maxWidth==0){// <br>if (hRatio<1) Ratio = hRatio; <br>}else if (maxHeight==0){ <br>if (wRatio<1) Ratio = wRatio; <br>}else if (wRatio<1 || hRatio<1){ <br>Ratio = (wRatio<=hRatio?wRatio:hRatio); <br>} <br>if (Ratio<1){ <br>w = w * Ratio; <br>h = h * Ratio; <br>} <br>objImg.height = h; <br>objImg.width = w; <br>} <br></script>

重点js:
function AutoResizeImage(maxWidth,maxHeight){
var objImg = document.getElementById("operImg");
var img = new Image();
img.src = objImg.src;
var hRatio;
var wRatio;
var Ratio = 1;
var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
if (maxWidth ==0 && maxHeight==0){
Ratio = 1;
}else if (maxWidth==0){//
if (hRatio}else if (maxHeight==0){
if (wRatio}else if (wRatioRatio = (wRatio}
if (Ratiow = w * Ratio;
h = h * Ratio;
}
objImg.height = h;
objImg.width = w;
}











