您的位置:首页 > 编程语言

按比例缩放图片的代码

2006-08-10 14:39 459 查看
<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>= 170/110){
if(image.width>170){
ImgD.width=170;
ImgD.height=(image.height*170)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>110){
ImgD.height=110;
ImgD.width=(image.width*110)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
调用事例如:<IMG width=170 height=110 src='"&rs("IndexPicUrl")&"'onload='javascript:DrawImage(this);' border=0>
只需要改变你需要的图片大小即可宽度170,高度110 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息