<script language="JavaScript">
<!--
//图片按比例缩放 [url]www.aiweb.cn[/url]
var flag=false;
function DrawImage(ImgD){
var p_w_picpath=new Image();
var iwidth = 170; //定义允许图片宽度
var iheight = 150; //定义允许图片高度
p_w_picpath.src=ImgD.src;
if(p_w_picpath.width>0 && p_w_picpath.height>0){
flag=true;
if(p_w_picpath.width/p_w_picpath.height>= iwidth/iheight){
if(p_w_picpath.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(p_w_picpath.height*iwidth)/p_w_picpath.width;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
else{
if(p_w_picpath.height>iheight){
ImgD.height=iheight;
ImgD.width=(p_w_picpath.width*iheight)/p_w_picpath.height;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
}
}
//调用:<img src="图片"
//-->
</script>
<!--
//图片按比例缩放 [url]www.aiweb.cn[/url]
var flag=false;
function DrawImage(ImgD){
var p_w_picpath=new Image();
var iwidth = 170; //定义允许图片宽度
var iheight = 150; //定义允许图片高度
p_w_picpath.src=ImgD.src;
if(p_w_picpath.width>0 && p_w_picpath.height>0){
flag=true;
if(p_w_picpath.width/p_w_picpath.height>= iwidth/iheight){
if(p_w_picpath.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(p_w_picpath.height*iwidth)/p_w_picpath.width;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
else{
if(p_w_picpath.height>iheight){
ImgD.height=iheight;
ImgD.width=(p_w_picpath.width*iheight)/p_w_picpath.height;
}else{
ImgD.width=p_w_picpath.width;
ImgD.height=p_w_picpath.height;
}
ImgD.alt=p_w_picpath.width+"×"+p_w_picpath.height;
}
}
}
//调用:<img src="图片"
//-->
</script>
转载于:https://blog.51cto.com/iyangchun/51552