获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP

<%

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

%>

<%

IMGPath="Test.jpg"

Set PP = New ImgWHInfo

W = PP.imgW(Server.Mappath(IMGPath))

H = PP.imgH(Server.Mappath(IMGPath))

Set pp = Nothing

%>

<%

Dim W,PXHeight

Dim Pp '//Proportion

If W=0 or W="" Then

PXWidth=0

PXHeight=0

Else

Pp=FormatNumber(W/H,2) '//长宽比

End If

If W>=H Then

If W>=300 Then

PXWidth=300

PXHeight=FormatNumber(300/Pp,0)

Else

PXWidth=W

PXHeight=H

End If

Else

If PHeight>=260 Then

PXHeight=260

PXWidth=FormatNumber(260*Pp,0)

Else

PXWidth=W

PXHeight=H

End If

End If

response.Write(PXWidth)

%>

<img src="Test.jpg" border="0" width=<%=PXWidth%>

height=<%=PXHeight%>>

时间: 2024-10-13 16:09:06

获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP的相关文章

获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP_ASP基础

<% 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 F

ASP程序获取图片宽度和高度的类源代码

程序|源代码|源代码 <% 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

ASP的一个获取图片宽度和高度的类

<%Class ImgWHInfo '获取图片宽度和高度的类,支持JPG,GIF,PNG,BMPDim ASOPrivate Sub Class_InitializeSet ASO=Server.CreateObject("ADODB.Stream")ASO.Mode=3ASO.Type=1ASO.OpenEnd SubPrivate Sub Class_TerminateErr.ClearSet ASO=NothingEnd Sub Private Function Bin2S

一个获取图片宽度和高度的类

<%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 Fun

ASP 程序获取图片宽度和高度

<% 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 Clas

ASP中取得图片宽度和高度的类(无组件)

无组件|无组件 <%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 Pri

ASP中取得图片宽度和高度的类(无组件)_应用技巧

ASP中取得图片宽度和高度的类(无组件) <% 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     Pri

PHP水印类,支持添加图片、文字、填充颜色区域的实现

*自己整理的一个水印类* 支持添加图片.文字.填充颜色区域 <?php /** * 图片加水印类,支持文字水印.透明度设置.自定义水印位置等. * 使用示例: * $obj = new WaterMask($imgFileName); //实例化对象 * $obj->$waterType = 1; //类型:0为文字水印.1为图片水印 * $obj->$transparent = 45; //水印透明度 * $obj->$waterStr = 'icp.niufee.com'; /

PHP 下载远程文件类(支持断点续传)

PHP 下载远程文件类,支持断点续传下载,代码内含有具体的调用说明.程序主要是使用 HTTP 协议下载文件,HTTP1.1协议必须指定文档结束后关闭链接,否则读取文档时无法使用feof判断结束,可以有两种使用方法,具体请下载查看源码. <?php /** * 下载远程文件类支持断点续传 */ class HttpDownload { private $m_url = ""; private $m_urlpath = ""; private $m_scheme