您现在的位置:首页 >> 软件开发 >> 内容

利用脚本控制显示图片大小

时间:2023-12-12 23:13:44 点击:

  核心提示:该程序可以控制图片的显示大小,控制在指定的长和宽下,显示图片会按比例缩小。如图片长度超出,则以指定长度作为图片显示长度,宽则按比例计算出来。反之一样。htmlheadmeta http-equiv='...

该程序可以控制图片的显示大小,控制在指定的长和宽下,显示图片会按比例缩小。
如图片长度超出,则以指定长度作为图片显示长度,宽则按比例计算出来。反之一样。


<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>

作者:站长 来源:网络
相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 陈工笔记(www.dui580.com) © 2024 版权所有 All Rights Reserved.
  • 站长:陈工 微信号:chengongbiji QQ:24498854
  • Powered by 陈工