当前位置: 代码网 > it编程>编程语言>其他编程 > 如何获知页面上的图象的实际尺寸?

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

2024年05月18日 其他编程 我要评论
如何获知页面上的图象的实际尺寸?<!--#include virtual="/intels/chunfeng/graphicdetect.asp"--><html><he

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

<!--#include virtual="/intels/chunfeng/graphicdetect.asp"-->
<html>

<head>
<title>
千花飞舞之获知图像尺寸</title>
</head>
<body>
<%
  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

function readgif(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(10), 4)
      hw(0) = hextodec(hexat(s,2) & hexat(s,1))
      hw(1) = hextodec(hexat(s,4) & hexat(s,3))
      ts.close
    readgif = hw
end function


function readwmf(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(14), 4)
      hw(0) = hextodec(hexat(s,2) & hexat(s,1))
      hw(1) = hextodec(hexat(s,4) & hexat(s,3))
      ts.close
    readwmf = hw
end function

function readbmp(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,4) & hexat(s,3))
      hw(1) = hextodec(hexat(s,8) & hexat(s,7))
      ts.close
    readbmp = hw
end function

function isdigit(c)
      if instr("0123456789", c) <> 0 then
      isdigit = true
      else
      isdigit = false
      end if
end function

function ishex(c)
      if instr("0123456789abcdefabcdef", c) <> 0 then
      ishex = true
      else
      ishex = false
      end if
end function

function hextodec(cadhex)
      dim n, i, ch, decimal
      decimal = 0
      n = len(cadhex)
      for i=1 to n
      ch = mid(cadhex, i, 1)
      if ishex(ch) then
      decimal = decimal * 16
      if isdigit(c) then
      decimal = decimal + ch
      else
      decimal = decimal + asc(ucase(ch)) - asc("a")
      end if
      else
      hextodec = -1
      end if
      next
      hextodec = decimal
end function
%>

 

[1]

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com