当前位置: 移动技术网 > IT编程>开发语言>其他编程 > 如何获知页面上的图象的实际尺寸?

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

2017年12月08日  | 移动技术网IT编程  | 我要评论

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

<!--#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]

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网