登录123 | 账号: 密码: 今天是: 加入收藏 返回首页 

同城供应求购,商机就在身边 免费企业商铺,免费发布商机 关注商业资讯,把握商业机会 同城库存二手,晒出您的宝贝,淘进新的宝贝
全国企业黄页大全,加入即可得到推广
返回同城123首页
同城123信息网,最全最专业的同城分类信息网
同城生活贴吧,贴出生活的精彩 同城房屋租售,卖房、买房、租房、出租 同城招聘求职,优秀人才/高薪岗位等您来 同城婚恋交友,寻找你的TA
免费无极限,广告任意发
供应求购 免费商铺 商业资讯 库存二手 黄页大全 生活贴吧 房屋租售 招聘求职 婚恋交友 自助广告

用asp获取图片高度宽度等信息的方法
发布时间:2010-11-10 22:32:24 发布人:jisu001 点击:236

<%
IMGPath="pics/test.gif"
Set PP=New ImgWHInfo  
W = PP.imgW(Server.Mappath(IMGPath))  
H = PP.imgH(Server.Mappath(IMGPath))
Set pp=Nothing
Response.Write("<img src='"&IMGPath&"' border=0><br>宽:"&W&";高:"&H)


'类代码
Class ImgWHInfo '获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP
    Dim ASO
    Private Sub Class_Initialize
        Set ASO=Server.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,I
        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,I
        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,I
        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 bFlag
        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(IMGPath)
        Dim FSO,IMGFile,FileExt,Arr
        Set FSO = Server.CreateObject("Scripting.FileSystemObject")
        If (FSO.FileExists(IMGPath)) Then
            Set IMGFile = FSO.GetFile(IMGPath)
            FileExt=FSO.GetExtensionName(IMGPath)
            Select Case FileExt
                Case "gif","bmp","jpg","png":
                Arr=GetImageSize(IMGFile.Path)
                imgW = Arr(1)
            End Select
            Set IMGFile=Nothing
        Else
            imgW = 0
        End If    
        Set FSO=Nothing
    End Function
    
    Public Function imgH(IMGPath)
        Dim FSO,IMGFile,FileExt,Arr
        Set FSO = server.CreateObject("Scripting.FileSystemObject")
        If (FSO.FileExists(IMGPath)) Then
            Set IMGFile = FSO.GetFile(IMGPath)
            FileExt=FSO.GetExtensionName(IMGPath)
            Select Case FileExt
                Case "gif","bmp","jpg","png":
                Arr=getImageSize(IMGFile.Path)
                imgH = Arr(2)
            End Select
            Set IMGFile=Nothing
        Else
            imgH = 0
        End If    
        Set FSO=Nothing
    End Function
End Class
%>

回复此帖
123发布网广告位【218】 123发布网广告位【219】
 ※ 发布回复   ↓请遵循123发布网同城生活贴吧/论坛发帖规则;↓寻一夜情、包养、招嫖类信息的一律全部删除,并报公安备案↓  
回复标题:  
回复内容:
上传图片:
验 证 码:  

123发布网广告位【220】 123发布网广告位【221】
网站首页 | 关于我们 | 广告业务 | 关于VIP | 免责声明 | 联系我们 | 设为首页 | 加入收藏 | 意见反馈 | 网站建设
123发布网 版权所有 www.123fbw.com  联系电话:18331151646  QQ:1016964448
 CopyRight © 2007-2016 All Right Reserved  联系站长  津ICP备10002728号  统计: