Javascript函数:
<script language="javascript">
function DrawImage(ImgD,FitWidth,FitHeight)
{
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0)
{
if(image.width/image.height>= FitWidth/FitHeight)
{
if(image.width>FitWidth)
{ //下面两行顺序不能颠倒(网上好多例子这两行顺序颠倒,实现不了等比例缩放) ImgD.height=(image.height*FitWidth)/image.width;
ImgD.width=FitWidth;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else
{
if(image.height>FitHeight)
{ //下面两行顺序不能颠倒
ImgD.width=(image.width*FitHeight)/image.height;
ImgD.height=FitHeight;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
} //alert(ImgD.width + "和" +ImgD.height);
}
</script>
然后调用:
<img border="0" src="images/出车申请效果图.gif" width="600" height="200" οnlοad="javascript:DrawImage(this,600,200);" />