ASP调用图片尺寸控制问题?
在用ASP调用目录下图片,怎样可以控制图片尺寸的比例.
条件:用FOR调用图片,而图片尺寸不定.但要按图片宽高的正常比例放大缩小.如何做到.
是否可以用ASP获得图片的长/宽/高.
问题点数:30、回复次数:4Top
1 楼climix(民主人士)回复于 2002-11-20 17:27:30 得分 15
<img src="&rs("pic")&" width=200 height=300> 或者说类似:rgb(255,255,255)Top
2 楼moonlight007(离人影)回复于 2002-11-21 16:13:28 得分 0
这个我知道,我要的是获取图片的长宽,然后按比例缩小.缩小问题我能解决,但始终取不到图片的尺寸.只取到图片的保存时间和大小.有哪位高手可以教我.Top
3 楼mx_lj(梦雪)回复于 2002-11-21 17:16:56 得分 15
以前珍藏了一篇文章,但我一直没试用一下(你自己看一下并试用吧!),我看很符合你的要求,希望对你有帮助!
◇◇自动获得图片的宽度与高度,并且自动按比例缩小◇◇
作者: 老克
!-- #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 then
msgstr01="jpg"
lngSize = len(checkdata)
flgFound = 0
strTarget = chrb(255) & chrb(216) & chrb(255)
flgFound = instrb(checkdata, strTarget)
lngPos = flgFound + 2
ExitLoop = false
do while ExitLoop = False and lngPos < lngSize
do while ascb(midb(checkdata, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if 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 if
loop
i_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_width
flag=2
else
flag=0
end if
end if
if flag=0 then
msgstr07="no image"
end if
msgstr=msgstr01 & msgstr02 & msgstr03 & msgstr04 & msgstr05 & msgstr06 & msgstr07
checkImageFormat=msgstr
end function
function lngConvert2(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))
end function
function lngConvert(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
len1=ascb(str1)
len2=ascb(str2)
lngConvert = clng(ascb(str1) + ascb(str2) * 256)
end function
FormSize = 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 function
Image=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%>
原著:老克
来自:chinaasp.com
Top
4 楼moonlight007(离人影)回复于 2002-11-22 16:12:55 得分 0
这个不行,有很多语句通不过.而且前面的包含文件是指什么呢.
也许是我不知道怎么调试,我在网上找了很多但没有一个成的.
有的可以取出数据但都不知道取的是什么有的数对上了换个文件取又全是错的了.Top




