图片等比缩放

<img src="http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif" border="0" onload="javascript:DrawImage(this,600,1520);"/>

//***********************************
// 函数名: DrawImage
// 作  用: 缩放图片比例
// 参  数: ImgD:图片项,Img设定宽度,Imgheight:设定高度
// 返回值: 无
//***********************************
function DrawImage(ImgD,Imgwidth,Imgheight){
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
    if(image.width/image.height>= Imgwidth/Imgheight){
   if(image.width>Imgwidth){ 
    ImgD.width=Imgwidth;
    ImgD.height=(image.height*Imgwidth)/image.width;
   }
   else{
    ImgD.width=image.width; 
    ImgD.height=image.height;
   }
   ImgD.alt=image.width+"×"+image.height;

     }
    else{
   if(image.height>Imgheight){ 
    ImgD.height=Imgheight;
    ImgD.width=(image.width*Imgheight)/image.height;    
   }
   else{
    ImgD.width=image.width; 
    ImgD.height=image.height;
   }

   ImgD.alt=image.width+"×"+image.height;
     }
    }
   else{
  ImgD.src="";
  ImgD.alt=""
    }
   }

原文地址:https://www.cnblogs.com/liuswi/p/2876177.html