上传照片的显示的时候比例缩放问题(在线等待...有用马上给分)

huiren 2004-11-29 04:22:52
在显示照片的时候,限制了一定的高度和宽度,当照片不是设定的高宽显示比例.照片就发生变形
有没有什么办法实现在显示只设定一个宽度,高度随宽的缩小而自动调整?

分不够可以再加!!!
多多帮忙!!
...全文
174 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiank 2004-11-29
  • 打赏
  • 举报
回复
楼上的,很好,建议采用
xulz 2004-11-29
  • 打赏
  • 举报
回复
->回复人: lisoon 正解
---------------------------------------------------------------

放入head里面
<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+"×"+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+"×"+image.height;
}
}
}
//-->
</script>

图片调用
<a href="<%=trim(rs("picurl"))%>" target="_blank"><img src="<%=trim(rs("imgurl"))%>" border="0" width="164" height="112" onload="javascript:DrawImage(this);"></a>

这样可以实现等比例缩放!
yqh1314 2004-11-29
  • 打赏
  • 举报
回复
来迟了!哎呀 可惜可惜要问题都解决了! 捧你场来了!
lisoon 2004-11-29
  • 打赏
  • 举报
回复
<script language="JavaScript">
var flag1=false;
function DrawImage1(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag1=true;
if(image.width/image.height>= 142/90){
if(image.width>142){
ImgD.width=142;
ImgD.height=(image.height*142)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>90){
ImgD.height=90;
ImgD.width=(image.width*90)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
</script>
应用onload="javascript:DrawImage1(this)">
liuyangxuan 2004-11-29
  • 打赏
  • 举报
回复
如果图片数量大的话,用缩略图组件,增大降低整体网站性能。
偶有个缓存数据的缩略图组件,楼主需要联系我。liuyangxuan@hotmail.com
yaniu 2004-11-29
  • 打赏
  • 举报
回复
也可用js来控制
  • 打赏
  • 举报
回复
http://www.lebo.cn里面的上传照片参考
hodat 2004-11-29
  • 打赏
  • 举报
回复
先获得图片的width和height


设置一个显示比例,,假设为 b1

如果 width / height 大于 b1
设置一个将要显示的width,假设为 w1
用 w1 * width / height
else
设置一个将要显示的height,假设为 h1
用 h1 * height / width


这样就可以按比例显示啦~~
kakalong 2004-11-29
  • 打赏
  • 举报
回复
设置匡架的 windth 和 height
cz0735 2004-11-29
  • 打赏
  • 举报
回复
你指定图片宽度或是高度就可以了。图片就会自动缩放。

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧