利用ASP获取设置图片尺寸大小
2008-08-20 17:25
423 查看
<%
imgpath="default_22.gif"
response.write "<img src='"&imgpath&"' border=0 "&SetAutoImg(280,260,imgpath)&"><br>宽:"&GetImgW(ImgPath)&";高:"&GetImgH(ImgPath)
function GetImgW(ImgPath)
set pp=new imgInfo
w=pp.imgW(server.mappath(ImgPath))
set pp=nothing
GetImgW=w
end function
function GetImgH(ImgPath)
set pp=new imgInfo
h=pp.imgH(server.mappath(ImgPath))
set pp=nothing
GetImgH=h
end function
function SetAutoImg(fitWidth,fitHeight,ImgPath)
hhRtn=0
wwRtn=0
set pp=new imgInfo
ww=pp.imgW(server.mappath(ImgPath))
hh=pp.imgH(server.mappath(ImgPath))
set pp=nothing
if ww>0 and hh>0 then
if ww/hh>=FitWidth/FitHeight then
wwRtn=fitWidth
hhRtn=(hh*FitWidth)/ww
else
hhRtn=fitHeight
wwRtn=(ww*FitHeight)/hh
end if
end if
SetAutoImg=" height='"&hhRtn&"'"&" width='"&wwRtn&"' "
end function
class imgInfo
dim aso
Private Sub Class_Initialize
set aso=CreateObject( "Adodb.Stream")
aso.Mode=3
aso.Type=1
aso.Open
End Sub
Private Sub Class_Terminate
err.clear
set aso=nothing
End Sub
Private Function Bin2Str(Bin)
Dim I, Str
For I=1 to LenB(Bin)
clow=MidB(Bin,I,1)
if ASCB(clow) <128 then
Str = Str & Chr(ASCB(clow))
else
I=I+1
if I <= LenB(Bin) then Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow))
end if
Next
Bin2Str = Str
End Function
Private Function Num2Str(num,base,lens)
dim ret
ret = ""
while(num >=base)
ret = (num mod base) & ret
num = (num - num mod base)/base
wend
Num2Str = right(string(lens, "0") & num & ret,lens)
End Function
Private Function Str2Num(str,base)
dim ret
ret = 0
for i=1 to len(str)
ret = ret *base + cint(mid(str,i,1))
next
Str2Num=ret
End Function
Private Function BinVal(bin)
dim ret
ret = 0
for i = lenb(bin) to 1 step -1
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal=ret
End Function
Private Function BinVal2(bin)
dim ret
ret = 0
for i = 1 to lenb(bin)
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal2=ret
End Function
Private Function getImageSize(filespec)
dim ret(3)
aso.LoadFromFile(filespec)
bFlag=aso.read(3)
select case hex(binVal(bFlag))
case "4E5089":
aso.read(15)
ret(0)= "PNG"
ret(1)=BinVal2(aso.read(2))
aso.read(2)
ret(2)=BinVal2(aso.read(2))
case "464947":
aso.read(3)
ret(0)= "GIF"
ret(1)=BinVal(aso.read(2))
ret(2)=BinVal(aso.read(2))
case "535746":
aso.read(5)
binData=aso.Read(1)
sConv=Num2Str(ascb(binData),2 ,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
while(len(sConv) <nBits*4)
binData=aso.Read(1)
sConv=sConv &Num2Str(ascb(binData),2 ,8)
wend
ret(0)= "SWF"
ret(1)=int(abs(Str2Num(mid(sConv,1*nBits+1,nBits),2)-Str2Num(mid(sConv,0*nBits+1,nBits),2))/20)
ret(2)=int(abs(Str2Num(mid(sConv,3*nBits+1,nBits),2)-Str2Num(mid(sConv,2*nBits+1,nBits),2))/20)
case "FFD8FF":
do
do: p1=binVal(aso.Read(1)): loop while p1=255 and not aso.EOS
if p1 >191 and p1<196 then exit do else aso.read(binval2(aso.Read(2))-2)
do:p1=binVal(aso.Read(1)):loop while p1 <255 and not aso.EOS
loop while true
aso.Read(3)
ret(0)= "JPG"
ret(2)=binval2(aso.Read(2))
ret(1)=binval2(aso.Read(2))
case else:
if left(Bin2Str(bFlag),2)= "BM" then
aso.Read(15)
ret(0)= "BMP"
ret(1)=binval(aso.Read(4))
ret(2)=binval(aso.Read(4))
else
ret(0)= ""
end if
end select
ret(3)= "width=""" & ret(1) &""" height=""" & ret(2) &""""
getimagesize=ret
End Function
Public Function imgW(pic_path)
Set fso1 = server.CreateObject( "Scripting.FileSystemObject")
If (fso1.FileExists(pic_path)) Then
Set f1 = fso1.GetFile(pic_path)
ext=fso1.GetExtensionName(pic_path)
select case ext
case "gif","bmp","jpg","png":
arr=getImageSize(f1.path)
imgW = arr(1)
end select
Set f1=nothing
else
imgW = 0
End if
Set fso1=nothing
End Function
Public Function imgH(pic_path)
Set fso1 = server.CreateObject( "Scripting.FileSystemObject")
If (fso1.FileExists(pic_path)) Then
Set f1 = fso1.GetFile(pic_path)
ext=fso1.GetExtensionName(pic_path)
select case ext
case "gif","bmp","jpg","png":
arr=getImageSize(f1.path)
imgH = arr(2)
end select
Set f1=nothing
else
imgH = 0
End if
Set fso1=nothing
End Function
End Class
%>
imgpath="default_22.gif"
response.write "<img src='"&imgpath&"' border=0 "&SetAutoImg(280,260,imgpath)&"><br>宽:"&GetImgW(ImgPath)&";高:"&GetImgH(ImgPath)
function GetImgW(ImgPath)
set pp=new imgInfo
w=pp.imgW(server.mappath(ImgPath))
set pp=nothing
GetImgW=w
end function
function GetImgH(ImgPath)
set pp=new imgInfo
h=pp.imgH(server.mappath(ImgPath))
set pp=nothing
GetImgH=h
end function
function SetAutoImg(fitWidth,fitHeight,ImgPath)
hhRtn=0
wwRtn=0
set pp=new imgInfo
ww=pp.imgW(server.mappath(ImgPath))
hh=pp.imgH(server.mappath(ImgPath))
set pp=nothing
if ww>0 and hh>0 then
if ww/hh>=FitWidth/FitHeight then
wwRtn=fitWidth
hhRtn=(hh*FitWidth)/ww
else
hhRtn=fitHeight
wwRtn=(ww*FitHeight)/hh
end if
end if
SetAutoImg=" height='"&hhRtn&"'"&" width='"&wwRtn&"' "
end function
class imgInfo
dim aso
Private Sub Class_Initialize
set aso=CreateObject( "Adodb.Stream")
aso.Mode=3
aso.Type=1
aso.Open
End Sub
Private Sub Class_Terminate
err.clear
set aso=nothing
End Sub
Private Function Bin2Str(Bin)
Dim I, Str
For I=1 to LenB(Bin)
clow=MidB(Bin,I,1)
if ASCB(clow) <128 then
Str = Str & Chr(ASCB(clow))
else
I=I+1
if I <= LenB(Bin) then Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow))
end if
Next
Bin2Str = Str
End Function
Private Function Num2Str(num,base,lens)
dim ret
ret = ""
while(num >=base)
ret = (num mod base) & ret
num = (num - num mod base)/base
wend
Num2Str = right(string(lens, "0") & num & ret,lens)
End Function
Private Function Str2Num(str,base)
dim ret
ret = 0
for i=1 to len(str)
ret = ret *base + cint(mid(str,i,1))
next
Str2Num=ret
End Function
Private Function BinVal(bin)
dim ret
ret = 0
for i = lenb(bin) to 1 step -1
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal=ret
End Function
Private Function BinVal2(bin)
dim ret
ret = 0
for i = 1 to lenb(bin)
ret = ret *256 + ascb(midb(bin,i,1))
next
BinVal2=ret
End Function
Private Function getImageSize(filespec)
dim ret(3)
aso.LoadFromFile(filespec)
bFlag=aso.read(3)
select case hex(binVal(bFlag))
case "4E5089":
aso.read(15)
ret(0)= "PNG"
ret(1)=BinVal2(aso.read(2))
aso.read(2)
ret(2)=BinVal2(aso.read(2))
case "464947":
aso.read(3)
ret(0)= "GIF"
ret(1)=BinVal(aso.read(2))
ret(2)=BinVal(aso.read(2))
case "535746":
aso.read(5)
binData=aso.Read(1)
sConv=Num2Str(ascb(binData),2 ,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
while(len(sConv) <nBits*4)
binData=aso.Read(1)
sConv=sConv &Num2Str(ascb(binData),2 ,8)
wend
ret(0)= "SWF"
ret(1)=int(abs(Str2Num(mid(sConv,1*nBits+1,nBits),2)-Str2Num(mid(sConv,0*nBits+1,nBits),2))/20)
ret(2)=int(abs(Str2Num(mid(sConv,3*nBits+1,nBits),2)-Str2Num(mid(sConv,2*nBits+1,nBits),2))/20)
case "FFD8FF":
do
do: p1=binVal(aso.Read(1)): loop while p1=255 and not aso.EOS
if p1 >191 and p1<196 then exit do else aso.read(binval2(aso.Read(2))-2)
do:p1=binVal(aso.Read(1)):loop while p1 <255 and not aso.EOS
loop while true
aso.Read(3)
ret(0)= "JPG"
ret(2)=binval2(aso.Read(2))
ret(1)=binval2(aso.Read(2))
case else:
if left(Bin2Str(bFlag),2)= "BM" then
aso.Read(15)
ret(0)= "BMP"
ret(1)=binval(aso.Read(4))
ret(2)=binval(aso.Read(4))
else
ret(0)= ""
end if
end select
ret(3)= "width=""" & ret(1) &""" height=""" & ret(2) &""""
getimagesize=ret
End Function
Public Function imgW(pic_path)
Set fso1 = server.CreateObject( "Scripting.FileSystemObject")
If (fso1.FileExists(pic_path)) Then
Set f1 = fso1.GetFile(pic_path)
ext=fso1.GetExtensionName(pic_path)
select case ext
case "gif","bmp","jpg","png":
arr=getImageSize(f1.path)
imgW = arr(1)
end select
Set f1=nothing
else
imgW = 0
End if
Set fso1=nothing
End Function
Public Function imgH(pic_path)
Set fso1 = server.CreateObject( "Scripting.FileSystemObject")
If (fso1.FileExists(pic_path)) Then
Set f1 = fso1.GetFile(pic_path)
ext=fso1.GetExtensionName(pic_path)
select case ext
case "gif","bmp","jpg","png":
arr=getImageSize(f1.path)
imgH = arr(2)
end select
Set f1=nothing
else
imgH = 0
End if
Set fso1=nothing
End Function
End Class
%>
相关文章推荐
- 利用ASP获取设置图片尺寸大小
- 利用js获取图片尺寸与图片大小(高度与宽度)
- Asp.net获取上传图片大小的尺寸!
- 利用js获取图片尺寸与图片大小(高度与宽度)
- 利用ASP得到图片尺寸大小
- python获取远程图片大小和尺寸的方法
- php 获取图片、swf的尺寸大小
- Android 获取屏幕尺寸及代码设置控件大小
- android图片缩放(指定大小) drawable获取图片后怎么设置图片大小
- 如何用JavaScript在浏览器端获取图片的原始尺寸大小?
- 手机网页图片自适应大小 background-size css 图片全屏 背景尺寸设置
- 设置了背景图片的TextView,其尺寸设置为wrap_content时,并不是适应文字内容大小
- 获取网站图片大小尺寸
- ASP.NET上传图片,服务器端验证,宽度,高度,文件类型,尺寸,文件大小,图片上传,图片格式检查
- ASP.NET MVC在服务端把异步上传的图片裁剪成不同尺寸分别保存,并设置上传目录的尺寸限制
- 获取网络图片的尺寸大小
- 获取android 手机屏幕的大小以及动态设置背景图片的两种方法;
- ASP.NET获取上传图片的大小
- js获取上传图片的尺寸大小
- ASP.NET MVC在服务端把异步上传的图片裁剪成不同尺寸分别保存,并设置上传目录的尺寸限制