利用ASP获得图象的实际尺寸的示例

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
  1. <!--#include virtual="/learn/test/lib_graphicdetect.asp"--> 
  2. <html><head> 
  3. <TITLE>dbtable.asp</TITLE> 
  4. </head> 
  5. <body bgcolor="#FFFFFF"> 
  6. <
  7. graphic="images/learnaspiconmain.gif" 
  8. HW = ReadImg(graphic) 
  9. Response.Write graphic & " Dimensions: " & HW(0) & "x" & HW(1) & "<br>
  10. response.write "<img src=""/" & graphic & """" 
  11. response.write height=""" & HW(0) & """ 
  12. response.write width=""" & HW(0) & "">" 
  13. %> 
  14. </body></html> 
  15. The library that is included is: 
  16. <
  17. Dim HW 
  18. Function AscAt(s, n) 
  19. AscAscAt = Asc(Mid(s, n, 1)) 
  20. End Function 
  21. Function HexAt(s, n) 
  22. HexHexAt = Hex(AscAt(s, n)) 
  23. End Function 
  24. Function isJPG(fichero) 
  25. If inStr(uCase(fichero), ".JPG") <> 0 Then 
  26. isJPG = true 
  27. Else 
  28. isJPG = false 
  29. End If 
  30. End Function 
  31. Function isPNG(fichero) 
  32. If inStr(uCase(fichero), ".PNG") <> 0 Then 
  33. isPNG = true 
  34. Else 
  35. isPNG = false 
  36. End If 
  37. End Function 
  38. Function isGIF(fichero) 
  39. If inStr(uCase(fichero), ".GIF") <> 0 Then 
  40. isGIF = true 
  41. Else 
  42. isGIF = false 
  43. End If 
  44. End Function 
  45. Function isBMP(fichero) 
  46. If inStr(uCase(fichero), ".BMP") <> 0 Then 
  47. isBMP = true 
  48. Else 
  49. isBMP = false 
  50. End If 
  51. End Function 
  52. Function isWMF(fichero) 
  53. If inStr(uCase(fichero), ".WMF") <> 0 Then 
  54. isWMF = true 
  55. Else 
  56. isWMF = false 
  57. End If 
  58. End Function 
  59. Function isWebImg(f) 
  60. If isGIF(f) or isJPG(f) or isPNG(f) or isBMP(f) or isWMF(f) Then 
  61. isWebImg = true 
  62. Else 
  63. isWebImg = true 
  64. End If 
  65. End Function 
  66. Function ReadImg(fichero) 
  67. If isGIF(fichero) Then 
  68. ReadImg = ReadGIF(fichero) 
  69. Else 
  70. If isJPG(fichero) Then 
  71. ReadImg = ReadJPG(fichero) 
  72. Else 
  73. If isPNG(fichero) Then 
  74. ReadImg = ReadPNG(fichero) 
  75. Else 
  76. If isBMP(fichero) Then 
  77. ReadImg = ReadPNG(fichero) 
  78. Else 
  79. If isWMF(fichero) Then 
  80. ReadImg = ReadWMF(fichero) 
  81. Else 
  82. ReadImg = Array(0,0) 
  83. End If 
  84. End If 
  85. End If 
  86. End If 
  87. End If 
  88. End Function 
  89. Function ReadJPG(fichero) 
  90. Dim fso, ts, s, HW, nbytes 
  91. HW = Array("","") 
  92. Set fso = CreateObject("Scripting.FileSystemObject") 
  93. Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
  94. s = Right(ts.Read(167), 4) 
  95. HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4)) 
  96. HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2)) 
  97. ts.Close 
  98. ReadJPG = HW 
  99. End Function 
  100. Function ReadPNG(fichero) 
  101. Dim fso, ts, s, HW, nbytes 
  102. HW = Array("","") 
  103. Set fso = CreateObject("Scripting.FileSystemObject") 
  104. Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
  105. s = Right(ts.Read(24), 8) 
  106. HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4)) 
  107. HW(1) = HexToDec(HexAt(s,7) & HexAt(s,8)) 
  108. ts.Close 
  109. ReadPNG = HW 
  110. End Function 
  111. Function ReadGIF(fichero) 
  112. Dim fso, ts, s, HW, nbytes 
  113. HW = Array("","") 
  114. Set fso = CreateObject("Scripting.FileSystemObject") 
  115. Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
  116. s = Right(ts.Read(10), 4) 
  117. HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1)) 
  118. HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3)) 
  119. ts.Close 
  120. ReadGIF = HW 
  121. End Function 
  122. Function ReadWMF(fichero) 
  123. Dim fso, ts, s, HW, nbytes 
  124. HW = Array("","") 
  125. Set fso = CreateObject("Scripting.FileSystemObject") 
  126. Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
  127. s = Right(ts.Read(14), 4) 
  128. HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1)) 
  129. HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3)) 
  130. ts.Close 
  131. ReadWMF = HW 
  132. End Function 
  133. Function ReadBMP(fichero) 
  134. Dim fso, ts, s, HW, nbytes 
  135. HW = Array("","") 
  136. Set fso = CreateObject("Scripting.FileSystemObject") 
  137. Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
  138. s = Right(ts.Read(24), 8) 
  139. HW(0) = HexToDec(HexAt(s,4) & HexAt(s,3)) 
  140. HW(1) = HexToDec(HexAt(s,8) & HexAt(s,7)) 
  141. ts.Close 
  142. ReadBMP = HW 
  143. End Function 
  144. Function isDigit(c) 
  145. If inStr("0123456789", c) <> 0 Then 
  146. isDigit = true 
  147. Else 
  148. isDigit = false 
  149. End If 
  150. End Function 
  151. Function isHex(c) 
  152. If inStr("0123456789ABCDEFabcdef", c) <> 0 Then 
  153. isHex = true 
  154. Else 
  155. ishex = false 
  156. End If 
  157. End Function 
  158. Function HexToDec(cadhex) 
  159. Dim n, i, ch, decimal 
  160. decimal = 0 
  161. n = Len(cadhex) 
  162. For i=1 To n 
  163. ch = Mid(cadhex, i, 1) 
  164. If isHex(ch) Then 
  165. decimaldecimal = decimal * 16 
  166. If isDigit(c) Then 
  167. decimaldecimal = decimal + ch 
  168. Else 
  169. decimaldecimal = decimal + Asc(uCase(ch)) - Asc("A") 
  170. End If 
  171. Else 
  172. HexToDec = -1 
  173. End If 
  174. Next 
  175. HexToDec = decimal 
  176. End Function 
  177. %> 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值