如何获知页面上的图象的实际尺寸?


下面两个文件: 
<!--#include virtual="/intels/chunfeng/graphicdetect.asp"--> 
<html> 
<head> 
<TITLE>图像尺寸</TITLE> 
</head> 
<body bgcolor="#FFFFFF"> 
<% 
graphic="images/intels.gif" 
HW = ReadImg(graphic) 
Response.Write graphic & " Dimensions: " & HW(0) & "x" & HW(1) 
& "<br>" 
response.write "<img src=""/" & graphic & """" 
response.write height=""" & HW(0) & """ 
response.write width=""" & HW(0) & "">" 
%> 
</body> 
</html>

------------------------ 
graphicdetect.asp 
<% 
Dim HW

Function AscAt(s, n) 
AscAt = Asc(Mid(s, n, 1)) 
End Function

Function HexAt(s, n) 
HexAt = Hex(AscAt(s, n)) 
End Function

Function isJPG(fichero) 
If inStr(uCase(fichero), ".JPG") <> 0 Then 
isJPG = true 
Else 
isJPG = false 
End If 
End Function

Function isPNG(fichero) 
If inStr(uCase(fichero), ".PNG") <> 0 Then 
isPNG = true 
Else 
isPNG = false 
End If 
End Function

Function isGIF(fichero) 
If inStr(uCase(fichero), ".GIF") <> 0 Then 
isGIF = true 
Else 
isGIF = false 
End If 
End Function

Function isBMP(fichero) 
If inStr(uCase(fichero), ".BMP") <> 0 Then 
isBMP = true 
Else 
isBMP = false 
End If 
End Function

Function isWMF(fichero) 
If inStr(uCase(fichero), ".WMF") <> 0 Then 
isWMF = true 
Else 
isWMF = false 
End If 
End Function

Function isWebImg(f) 
If isGIF(f) Or isJPG(f) Or isPNG(f) Or isBMP(f) Or isWMF(f) 
Then 
isWebImg = true 
Else 
isWebImg = true 
End If 
End Function

Function ReadImg(fichero) 
If isGIF(fichero) Then 
ReadImg = ReadGIF(fichero) 
Else 
If isJPG(fichero) Then 
ReadImg = ReadJPG(fichero) 
Else 
If isPNG(fichero) Then 
ReadImg = ReadPNG(fichero) 
Else 
If isBMP(fichero) Then 
ReadImg = ReadPNG(fichero) 
Else 
If isWMF(fichero) Then 
ReadImg = ReadWMF(fichero) 
Else 
ReadImg = Array(0,0) 
End If 
End If 
End If 
End If 
End If 
End Function

Function ReadJPG(fichero) 
Dim fso, ts, s, HW, nbytes 
HW = Array("","") 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
s = Right(ts.Read(167), 4) 
HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4)) 
HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2)) 
ts.Close 
ReadJPG = HW 
End Function

Function ReadPNG(fichero) 
Dim fso, ts, s, HW, nbytes 
HW = Array("","") 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
s = Right(ts.Read(24), 8) 
HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4)) 
HW(1) = HexToDec(HexAt(s,7) & HexAt(s,8)) 
ts.Close 
ReadPNG = HW 
End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值