文秘频道 | 图片频道 | 教程频道 | 教案频道 | 加入收藏 | 会员投稿
当前位置:教程荟萃首页 >> 编程开发 >> JAVA >> 不让你的缩略图变形代码
不让你的缩略图变形代码
2008-03-25 13:57:56  作者:  来源:互联网  浏览次数:3  文字大小:【】【】【

我们在首页提缩略图的时候会遇到有的是800×600图片还有600×800图片,如果我们把缩略图大小设置成固定大小,其中肯定有一个图会变形,下面代码可以帮你解决这个问题。
  下面代码可以加到网页的任何位置:
Quote:
<script language="JavaScript">

var flag=false;
function DrawImage(ImgD,imageWidth,imageHeight) {

var image=new Image();

image.src=ImgD.src;

if(image.width>0 && image.height>0){

flag=true;
if(image.width/image.height>= imageWidth/imageHeight){

if(image.width>imageWidth){
ImgD.width=imageWidth;

ImgD.height=(image.height*imageWidth)/image.width;

}else{
ImgD.width=image.width;

ImgD.height=image.height;

}

}
else{

if(image.height>imageHeight){

ImgD.height=imageHeight;

ImgD.width=(image.width*imageHeight)/image.height;

}else{

ImgD.width=image.width;

ImgD.height=image.height;

}
}
}

}

</script>

下面代码是图片设置:

<img src="<%=rs("pic")%>" border="0"  />

0

顶一下

0

踩一下
友情链接 | 诚聘英才 | 关于我们 | 版权声明 | 联系我们 | 广告服务
  •     大智学场copyright©2007 站长QQ:138290388 闽ICP备05004390号 
    声明:站内提供的所有教程文章均是由网上搜集或网友提供,若侵犯了你的版权利益,敬请来信通知我们!