如何将上传的图片中尺寸大在显示时缩小,尺寸小的不变

zhobin 2003-09-25 07:42:33
如何将上传的图片中尺寸大在显示时缩小,尺寸小的不变
...全文
359 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
h2high 2003-11-06
  • 打赏
  • 举报
回复
<img src="http://www.csdn.net/images/homeimage/csdn.gif" onLoad="with(this){(width/height>=4/3)?(width=(width>40)?40:width):(height=(height>30)?30:height);}">

图片不能设置width和height
参数可以自己改
宽高比是4/3
宽度设置40
高度设置30
stefli 2003-09-26
  • 打赏
  • 举报
回复
我上面的那些数字,你可以根据实际的显示情况改了。
挺好用的。
jcjks杨 2003-09-26
  • 打赏
  • 举报
回复
我的这段呢是假设你要显示的图片都放在某文件夹下,那它可以自动遍历该文件夹下的所有图片并做显示,有大小限制了,单击后可另开一页单独显示,不过显示的我就没帖了,你看一下吧




<%
DIM PhotoPath,VarPhotoWidth,VarPhotoHeight '要求的图片路径及尺寸
DIM WebPhotoPath,PhotoWidth,PhotoHeight '图片显示的实际尺寸
DIM trNo,TempName '用于标记是否应该换行

PhotoPath="images\school"
VarPhotoWidth=120
VarPhotoHeight=120
trNo=0

Set qswh=new qswhImg '得到照片的大小
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Request.ServerVariables("APPL_PHYSICAL_PATH") & PhotoPath)
Set fc = f.Files
For Each f1 in fc
ext=fso.GetExtensionName(f1.path)
If ext="gif" Or ext="jpg" Or ext="jpeg" Then
arr=qswh.getImageSize(f1.path)
If arr(1)<VarPhotoWidth Then PhotoWidth=arr(1) Else PhotoWidth=VarPhotoWidth
If arr(2)<VarPhotoHeight Then PhotoHeight=arr(2) Else PhotoHeight=VarPhotoHeight

WebPhotoPath="/yngfgx/images/school/" & f1.name
If (trNo Mod 3)=0 Then
Response.Write "<tr width='100%' height='140'>"
End If
TempName=Left(f1.name,Len(f1.name)-Len(ext)-1)
Response.write "<td width='30%' height='130' align='center'>"
Response.Write "<img style='cursor:hand;'border=1 src='" & WebPhotoPath & "' width='" & PhotoWidth & "' height='" & PhotoHeight & "' alt=" & TempName & " onClick=javascript:openWindow('/yngfgx/subsite/school/dispic.asp?picpath=" & WebPhotoPath & "&picwidth=" & arr(1) & "&picheight=" & arr(2) & "','" & arr(2) & "','" & arr(1) & "');>"
Response.Write "<br><font size='2' face='宋体'>" & TempName & "</font>"
Response.Write "</td>"
'response.write "<br>" & arr(0) & " " & arr(3) & ":" & f1.name & " width:" & arr(1) & " height:" & arr(2)
trNo=trNo+1
End If
Next
Set fc=nothing
Set f=nothing
Set fso=nothing
Set qswh=nothing

%>
astra1 2003-09-26
  • 打赏
  • 举报
回复
如果你的宽和高都有限制,而且要图片保持原有的比例,必须这样做

<script>
function checkImgSize(imgIn)
{
var maxWidth=80;
var maxHeight=60;
if(imgIn.width>imgIn.height)
{
if(imgIn.width>maxWidth)
imgIn.width=maxWidth;
}
else
{
if(imgIn.height>maxHeight)
imgIn.height=maxHeight;
}
}
</script>
<img src="images/imgNA.gif" onload="javascript:checkImgSize(this)">
testzz 2003-09-25
  • 打赏
  • 举报
回复
只指定宽度不就好了?
<IMG SRC=""$2"" border=0 onload='javascript:if(this.width>399)this.width=399'>
h2high 2003-09-25
  • 打赏
  • 举报
回复
只指定宽度不就好了?
<img src="a.jpg" width=360>
宽度本来就是可以自动按比例缩放的
xyp730000 2003-09-25
  • 打赏
  • 举报
回复
这和这东西有区别吗

<img src="a.jpg" width=360 height=270>
BainStudio 2003-09-25
  • 打赏
  • 举报
回复
同上.
stefli 2003-09-25
  • 打赏
  • 举报
回复
<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>= 360/270){
if(image.width>360){
ImgD.width=360;
ImgD.height=(image.height*360)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>270){
ImgD.height=270;
ImgD.width=(image.width*270)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>

<img src="a.gif" class="border" onload="javascript:DrawImage(this);">

28,406

社区成员

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

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