该程序可以控制图片的显示大小,控制在指定的长和宽下,显示图片会按比例缩小。
如图片长度超出,则以指定长度作为图片显示长度,宽则按比例计算出来。反之一样。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 164/112){
if(image.width>164){
ImgD.width=164;
ImgD.height=(image.height*164)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"x"+image.height;
}
else{
if(image.height>112){
ImgD.height=112;
ImgD.width=(image.width*112)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"x"+image.height;
}
}
}
//-->
</script>
</head>
<body>
<table border="1" height="155" width="200" >
<tr>
<td width=183 height="149" align="center"><img src="UploadFiles/p3.jpg" border="0" onload="javascript:DrawImage(this);"></td>
</tr>
</table>
</body>
</html>