ASP中取得图片宽度和高度的类
来源:CSDN 发布时间:2008-10-29 12:38:00
标签:类,图片,asp
获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP
我们可以使用这个类来处理图片的显示。
<%
Class ImgWHInfo
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
Response.Write("<img src='"&IMGPath&"' border=0><br>宽:"&W&";高:"&H)
%>
0
投稿
猜你喜欢
- 1、Caused by: com.MySQL.jdbc.exceptions.jdbc4.CommunicationsException:T
- 远程调用使得调用远程服务器的对象、方法的方式就和调用本地对象、方法的方式差不多,因为我们通过网络编程把这些都隐藏起来了。远程调用是分布式系统
- 本文介绍了一个较为通用的获取 checkbox 值的方法,希望对新手有用。<script type="text/javasc
- 因为要做移动梦网WAP的一些接口,所以要用到这种方式,接下来会有ASP.net版本的,这个是ASP版本的,利用了MSXML2.XMLHTTP
- 即使在urlencode之前str.decode(“cp936″).encode(“utf-8″)做了编码转换也是没用的。后来查询手册查到一
- Python用input输入列表的方法使用input输入数据时,使用逗号隔开列表的每一项,再使用ast.literal_eval()方法转成
- 去除字符串左右两端的空格,在vbscript里面可以轻松地使用 trim、ltrim 或 rtrim,但在js
- 处理数据时我们经常需要从数组中随机抽取元素,这时候我们可以考虑使用np.random.choice()函数语法格式numpy.random.
- 本文实例讲述了GO语言标准错误处理机制error用法。分享给大家供大家参考。具体分析如下:在 Golang 中,错误处理机制一般是函数返回时
- 本脚本为本人在性能测试过程中编写,用于对进程状态的监控,也可以用于日常的监控,适用性一般,扩展性还行# -*- coding: UTF-8
- 前言Django原生自带的数据库支持是sqlite,但是我们现在常用的数据库一般是mysql,mangodb等数据库。所以我们要改变数据库的
- 根据django官方文档建议,开发过程中会把生成的migrations提交到git中。由于各种原因,会有一些场景需要重置migrations
- 1、引言小 * 丝:鱼哥,你说这就快到圣诞节了,我应该送女神什么礼物呢?小鱼:你的女神又不缺什么礼物,倒不如送点惊喜?小 * 丝:送什么惊喜呢?小鱼
- 使用cv2对视频进行切割import cv2def clip_video(source_video, target_video, start
- 测了一下django、flask、bottle、tornado 框架本身最简单的性能。对django的性能完全无语了。django、flas
- 至于对好广告的评判,不同的人有不同的标准,一些人认为那些打动人、有新意、有共鸣的广告是好广告,另一些人的观点则是:观众喜欢与否,不是广告好与
- 在Windows平台上安装mysql模块用于Python开发用python连接mysql的时候,需要用的安装版本,源码版本容易有错误提示。下
- 本节描述openGauss数据库在虚拟机VirtualBox+openEuler上的安装配置。1、虚拟机VirtualBox下载及安装步骤
- 1.order by rand()数据多了极慢,随机性非常好,适合非常小数据量的情况。SELECT * FROM table_name AS
- Python“json.decoder.JSONDecodeError: Expecting value: line 1