ASP中如何获得数据库中保存的图片的长和宽哪?

mvp2000 2001-07-27 02:55:17
如果图片保存在数据库里,可以获得她的长和宽吗?
如果图片上传到服务器上,可以获得吗?
怎么做?谢谢!
...全文
89 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
neweb 2001-07-31
  • 打赏
  • 举报
回复
不敢称什么高手啊,我的email:mg1616@hnbiz.com, QQ我上得很少
mvp2000 2001-07-31
  • 打赏
  • 举报
回复
newnb果然是高手,请问可以叫个朋友吗?

我的QQ是59360399
Email是mvp2000@21cn.com
neweb 2001-07-28
  • 打赏
  • 举报
回复
下面这个文件应该能完全满足你的“图片上传到服务器上”的要求了,它能够输出 图片信息(格式,宽,高,色深),遇到同名文件它能自动加序列号,避免覆盖,比如将上传的 some.jpg 自动另存为 some2.jpg。

<%
if Request.ServerVariables("Content_Length") > 0 then

formsize = Request.TotalBytes
formdata = Request.BinaryRead (FormSize) '获取上传数据

file = GetFile(formsize,formdata)
ImageInfo = checkImageFormat(file)

PosBeg = instrb(formdata,chrb(13)&chrb(10)&chrb(13)&chrb(10)) + 4

strTXT = midb(formdata,1,PosBeg) '取出文字
strTXT = Bin2Str(strTXT) '二进制转换成普通文字

FileName = GetFileName(strTxt)
FilePath = Server.MapPath("/") &"\"
set fso = Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists (FilePath&FileName) then
File1 = left(FileName,Len(FileName)-4)
File2 = right(FileName,4)
seq = 2
while fso.FileExists (FilePath&File1&Cstr(seq)&File2)
seq = seq+1
wend
FileName = FilePath&File1&Cstr(seq)&File2
end if
set fso = nothing

set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Mode = 3 'adModeReadWrite
objStream.Open
objStream.Write formdata
objStream.SaveToFile FileName,2
objStream.Close
set objStream = nothing

end if

Function GetFileName(strTxt)
bb = instr(1,strTXT,"filename=")
if bb > 1 then
PStart = bb + 10
PEnd = instr(PStart,strTXT,Chr(34))
GetFileName = mid(strTXT,PStart,PEnd - PStart)
if GetFileName <> empty then
Pos = instr(1,GetFileName,"\")
while Pos > 0
Pos1 = instr(Pos+1,GetFileName,"\")
if Pos1>Pos then
Pos=Pos1
else
Pos1=Pos
Pos=0
end if
wend
GetFileName = right(GetFileName,Len(GetFileName)-Pos1)
end if
end if
End function

Function Bin2Str(binstr)
ccc = ""
varlen = LenB(binstr)
For i=1 To varlen
clow = MidB(binstr,i,1)
If AscB(clow) > 127 and i<varLen Then
ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
i=i+1
Else
ccc = ccc & Chr(AscB(clow))
End If
Next
bin2str = ccc
End Function

Function GetTxt(fmField,strTxt)
bb = instr(1,strTXT,fmField) '如果找不到则退出循环
if bb > 1 then
strLen = len(fmField) + 2 '表单中可能有多个同名变量(用在有主表与明细表中的数据更新中)
PStart = bb + strLen + 3
PEnd = instr(PStart,strTXT,Chr(34)) - 2
GetTxt = mid(strTXT,PStart,PEnd - PStart)
end if
End function

Function GetFile(formsize,formdata)
bncrlf = chrb(13) & chrb(10)
divider = leftb(formdata,instrb(formdata,bncrlf)-1) 'formdata第一个bncrlf左边的数据
datastart = instrb(formdata,bncrlf & bncrlf)+4 '两个bncrlf右边的数据的起始位
dataend = instrb(datastart+1,formdata,divider)-datastart
GetFile = midb(formdata,datastart,dataend)
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

'---------------------------------------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 &","& i_Depth
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 &","& i_Depth

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 &","& i_Depth

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

%>
<HTML>
<HEAD>
<META content="text/html; charset=GB2312" http-equiv=Content-Type>
</HEAD>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>
<br>

<table width="60%" border="0" cellspacing="0" cellpadding="0" bordercolorlight="#666666" bordercolordark="#FFFFFF" align="center">
<tr>
<td> <br>
<form name="form1" method="post" action="" enctype="multipart/form-data">
文件:<input type="file" name="file1" size="50"><br>
<!-- 说明:<input type="text" name="info" size="50"><br> -->
<input type="submit" name="Submit" value="上传">
</FORM>
</td>
</tr>
</table>
图片信息(格式,宽,高,色深):<%=ImageInfo%>
</BODY>
</HTML>
powderbun 2001-07-27
  • 打赏
  • 举报
回复
看这图片什么格式,然后读取相应字节(里面有图片的长宽),进行转换。

我的想法而已,没实践过。

28,408

社区成员

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

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