图片按比例缩放大小

<SCRIPT LANGUAGE="JavaScript">
<!--
//图片等比例缩放

var FitWidth = 250;  //图片宽度
var FitHeight = 176; //图片高度
function ResizePic(ImgTag)
{
    var image = new Image();
image.src = ImgTag.src;
if(image.width>0 && image.height>0){
  if(image.width/image.height >= FitWidth/FitHeight){
   if(image.width > FitWidth){
    ImgTag.width = FitWidth;
    ImgTag.height = (image.height*FitWidth)/image.width;
   }
   else{
    ImgTag.width = image.width;
    ImgTag.height = image.height;
   }
  }
  else{
   if(image.height > FitHeight){
    ImgTag.height = FitHeight;
    ImgTag.width = (image.width*FitHeight)/image.height;
   }
   else{
    ImgTag.width = image.width;
    ImgTag.height = image.height;
   }
  }
}
}
-->
</script>

<img width="30" height="30" src="../honor/1.jpg" onload="javascript:ResizePic(this)">

你可能感兴趣的:(图片)