怎样用代码实现对图片进行自动限制图片尺寸?如把300*200的图片缩成100*80 response.write "<img height=80 width=100 src='" & rs("img") & '">" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 同意楼上的,只怕littleBenhorse不是这个意思吧 谢谢各位!我想表达的意思是,能有一个单选栏,用户可以选择现实图片的尺寸,代码如下,那位大哥能给改一下,谢谢了!<%@LANGUAGE="VBSCRIPT"%><!--#include file="Connections/CONNSQL.asp" --><%set Recordset1 = Server.CreateObject("ADODB.Recordset")Recordset1.ActiveConnection = MM_CONNSQL_STRINGRecordset1.Source = "SELECT * FROM dbo.SHOW"Recordset1.CursorType = 0Recordset1.CursorLocation = 2Recordset1.LockType = 3Recordset1.Open()Recordset1_numRows = 0%><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body bgcolor="#FFFFFF" text="#000000"><p> </p><p> </p><p> </p><img src="<%=(Recordset1.Fields.Item("S_PICURL").Value)%>" width="100" height="80"> <form name="form1" method="post" action=""> <input type="radio" name="radiobutton" value="radiobutton"> 100*80 <input type="radio" name="radiobutton" value="radiobutton"> 200*160 <input type="submit" name="Submit" value=" 确认修改"></form></body></html><%Recordset1.Close()%>%> 如果是为了显示效果完全可以象net_lover(孟子E章)那样来控制啊但是如果你想通过html来把图片的大小改了那好象是不可能啊<script>function ca(){for (i=0;i<document.images.length;i++){document.images[i].style.width=100document.images[i].style.height=80}}</script><img src="sd.gif"><img src="sd.gif"><input type="Button" onclick="ca()"> 自动获得图片的宽度与高度,并且自动按比例缩小<!-- #include file="db.inc" --><%'---------------------------------------RETURN THE IMAGE FORMAT--------------------function checkImageFormat(checkdata)'--return: A,B,C (A is image format; B is height pixels; C is width pixels; D is color depth) flag=0 '''''''0 is not jpg/gif/png image; 1 is jpg/gif/png'-------------------------------------------------------check jpg----------------if flag=0 then tempstr=Leftb(checkdata,10)tstr=chrb(255)&chrb(216)&chrb(255)&chrb(224)&chrb(0)&chrb(16)&chrb(74)&chrb(70)&chrb(73)&chrb(70)if strcomp(tempstr,tstr,0)=0 thenmsgstr01="jpg"lngSize = len(checkdata)flgFound = 0strTarget = chrb(255) & chrb(216) & chrb(255)flgFound = instrb(checkdata, strTarget)lngPos = flgFound + 2ExitLoop = falsedo while ExitLoop = False and lngPos < lngSizedo while ascb(midb(checkdata, lngPos, 1)) = 255 and lngPos < lngSizelngPos = lngPos + 1loopif ascb(midb(checkdata, lngPos, 1)) < 192 or ascb(midb(checkdata, lngPos, 1)) > 195 thenlngMarkerSize = lngConvert2(midb(checkdata, lngPos + 1, 2))lngPos = lngPos + lngMarkerSize + 1elseExitLoop = Trueend ifloopi_Height = lngConvert2(midb(checkdata, lngPos +4, 2))i_Width = lngConvert2(midb(checkdata, lngPos +6, 2))i_Depth = 2 ^ (ascb(midb(checkdata, lngPos + 8, 1)) * 8)msgstr02=","& i_height & "," & i_widthflag=2elseflag=0end ifend if'--------------------------------------------------check gif--------------------------------if flag=0 thentempstr=Leftb(checkdata,6)tstr=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(57)&chrb(97)tstr2=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(55)&chrb(97)if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 thenmsgstr03="gif"i_width=lngConvert(midb(checkdata,7,2))i_height=lngConvert(midb(checkdata,9,2))i_Depth = 2 ^ ((ascb(midb(checkdata, 11, 1)) and 7) + 1)msgstr04=","& i_height & ","& i_width flag=2else flag=0end ifend if'---------------------------------------------------check png------------------------------if flag=0 then tempstr=Leftb(checkdata,4)tstr=chrb(137)&chrb(80)&chrb(78)&chrb(71)if strcomp(tempstr,tstr,0)=0 thenmsgstr05="png"i_Width = lngConvert2(midb(checkdata, 19, 2))i_Height = lngConvert2(midb(checkdata, 23, 2))i_Depth = lngConvert(midb(checkdata, 25, 2))select case ascb(right(i_Depth,1))case 0i_Depth = 2 ^ (asc(left(i_Depth, 1)))gfxSpex = Truecase 2i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 3)gfxSpex = Truecase 3i_Depth = 2 ^ (asc(left(i_Depth, 1))) '8gfxSpex = Truecase 4i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 2)gfxSpex = Truecase 6i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 4)gfxSpex = Truecase elsei_Depth = -1end selectmsgstr06=","& i_height & ","& i_widthflag=2else flag=0end ifend ifif flag=0 then msgstr07="no image"end ifmsgstr=msgstr01 & msgstr02 & msgstr03 & msgstr04 & msgstr05 & msgstr06 & msgstr07checkImageFormat=msgstrend functionfunction lngConvert2(strTemp)str1=leftb(strTemp,1)str2=rightb(strTemp,1)lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))end functionfunction lngConvert(strTemp)str1=leftb(strTemp,1)str2=rightb(strTemp,1)len1=ascb(str1)len2=ascb(str2)lngConvert = clng(ascb(str1) + ascb(str2) * 256)end functionFormSize = Request.TotalBytes FormData = Request.BinaryRead( FormSize )function ImageUp(formsize,formdata) bncrlf=chrb(13) & chrb(10) divider=leftb(formdata,instrb(formdata,bncrlf)-1)datastart=instrb(formdata,bncrlf&bncrlf)+4dataend=instrb(datastart+1,formdata,divider)-datastartimageup=midb(formdata,datastart,dataend)end functionImage=ImageUp (FormSize,Formdata) arrayMessage=split(checkImageFormat(image),",")'*********************************%><% 'on error resume nextif arrayMessage(1)>600 OR arrayMessage(2)>500 then%> <script language="javascript">alert("您所选择的图片的尺寸不符合要求!应在 高*宽 600*500 之间,请重新选择图片!另外注意图片只能从本地目录上传!")self.close()</script><% Else......<%End if%> -----------------------------------------------------------------主要看中间三段check jpgcheck gifcheck png 关于jquery的hover事件 关于Spry折叠式的设置 有没万能的网页播放器? 如何用Javacript实现树状目录的节点添加功能 ASP.NET打印问题(水晶报表-〉pdf-〉打印输出) 动态的给dojo Tree 控件添加TreeNode节点 怎样把array用字符串赋值 小问题:SUBMIT() 如何在JavaScript中引入类? jsp 代码部分怎么定义java script的变量? 是这样写的吗:out.println("var CourseID="""+strCourseID+""";\r\n"); 很简单的,请会的告诉我 请教大家一个问题,都过来看看哦!
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/CONNSQL.asp" -->
<%
set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_CONNSQL_STRING
Recordset1.Source = "SELECT * FROM dbo.SHOW"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<p> </p>
<p> </p>
<img src="<%=(Recordset1.Fields.Item("S_PICURL").Value)%>" width="100" height="80">
<form name="form1" method="post" action="">
<input type="radio" name="radiobutton" value="radiobutton">
100*80
<input type="radio" name="radiobutton" value="radiobutton">
200*160
<input type="submit" name="Submit" value=" 确认修改">
</form>
</body>
</html>
<%
Recordset1.Close()
%>
%>
但是如果你想通过html来把图片的大小改了
那好象是不可能啊<script>
function ca()
{
for (i=0;i<document.images.length;i++)
{
document.images[i].style.width=100
document.images[i].style.height=80
}
}
</script>
<img src="sd.gif">
<img src="sd.gif">
<input type="Button" onclick="ca()">
<%
'---------------------------------------RETURN THE IMAGE FORMAT--------------------
function checkImageFormat(checkdata)
'--return: A,B,C (A is image format; B is height pixels; C is width pixels; D is color depth) flag=0 '''''''0 is not jpg/gif/png image; 1 is jpg/gif/png'-------------------------------------------------------check jpg----------------
if flag=0 then
tempstr=Leftb(checkdata,10)
tstr=chrb(255)&chrb(216)&chrb(255)&chrb(224)&chrb(0)&chrb(16)&chrb(74)&chrb(70)&chrb(73)&chrb(70)if strcomp(tempstr,tstr,0)=0 then
msgstr01="jpg"
lngSize = len(checkdata)
flgFound = 0strTarget = chrb(255) & chrb(216) & chrb(255)
flgFound = instrb(checkdata, strTarget)lngPos = flgFound + 2
ExitLoop = falsedo while ExitLoop = False and lngPos < lngSizedo while ascb(midb(checkdata, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loopif ascb(midb(checkdata, lngPos, 1)) < 192 or ascb(midb(checkdata, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(checkdata, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end ifloopi_Height = lngConvert2(midb(checkdata, lngPos +4, 2))
i_Width = lngConvert2(midb(checkdata, lngPos +6, 2))
i_Depth = 2 ^ (ascb(midb(checkdata, lngPos + 8, 1)) * 8)msgstr02=","& i_height & "," & i_width
flag=2
else
flag=0
end if
end if
'--------------------------------------------------check gif--------------------------------
if flag=0 then
tempstr=Leftb(checkdata,6)
tstr=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(57)&chrb(97)
tstr2=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(55)&chrb(97)
if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 then
msgstr03="gif"i_width=lngConvert(midb(checkdata,7,2))
i_height=lngConvert(midb(checkdata,9,2))
i_Depth = 2 ^ ((ascb(midb(checkdata, 11, 1)) and 7) + 1)
msgstr04=","& i_height & ","& i_width flag=2
else
flag=0
end if
end if'---------------------------------------------------check png------------------------------
if flag=0 then
tempstr=Leftb(checkdata,4)
tstr=chrb(137)&chrb(80)&chrb(78)&chrb(71)
if strcomp(tempstr,tstr,0)=0 then
msgstr05="png"i_Width = lngConvert2(midb(checkdata, 19, 2))
i_Height = lngConvert2(midb(checkdata, 23, 2))
i_Depth = lngConvert(midb(checkdata, 25, 2))select case ascb(right(i_Depth,1))
case 0
i_Depth = 2 ^ (asc(left(i_Depth, 1)))
gfxSpex = True
case 2
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 3)
gfxSpex = True
case 3
i_Depth = 2 ^ (asc(left(i_Depth, 1))) '8
gfxSpex = True
case 4
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 2)
gfxSpex = True
case 6
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 4)
gfxSpex = True
case else
i_Depth = -1
end select
msgstr06=","& i_height & ","& i_widthflag=2
else
flag=0
end if
end if
if flag=0 then
msgstr07="no image"
end if
msgstr=msgstr01 & msgstr02 & msgstr03 & msgstr04 & msgstr05 & msgstr06 & msgstr07checkImageFormat=msgstr
end functionfunction lngConvert2(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))
end functionfunction lngConvert(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
len1=ascb(str1)
len2=ascb(str2)
lngConvert = clng(ascb(str1) + ascb(str2) * 256)
end functionFormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )function ImageUp(formsize,formdata)
bncrlf=chrb(13) & chrb(10)
divider=leftb(formdata,instrb(formdata,bncrlf)-1)
datastart=instrb(formdata,bncrlf&bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
imageup=midb(formdata,datastart,dataend)
end functionImage=ImageUp (FormSize,Formdata) arrayMessage=split(checkImageFormat(image),",")
'*********************************%><%
'on error resume next
if arrayMessage(1)>600 OR arrayMessage(2)>500 then%>
<script language="javascript">
alert("您所选择的图片的尺寸不符合要求!应在 高*宽 600*500 之间,请重新选择图片!另外注意图片只能从本地目录上传!")
self.close()
</script>
<% Else
......
<%End if%>
-----------------------------------------------------------------
主要看中间三段
check jpg
check gif
check png