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

  1. <!--#includevirtual="/learn/test/lib_graphicdetect.asp"-->
  2. <html><head>
  3. <TITLE>dbtable.asp</TITLE>
  4. </head>
  5. <bodybgcolor="#FFFFFF">
  6. <%
  7. graphic="images/learnaspiconmain.gif"
  8. HW=ReadImg(graphic)
  9. Response.Writegraphic&"Dimensions:"&HW(0)&"x"&HW(1)&"<br>"
  10. response.write"<imgsrc=""/"&graphic&""""
  11. response.writeheight="""&HW(0)&"""
  12. response.writewidth="""&HW(0)&"">"
  13. %>
  14. </body></html>
  15. Thelibrarythatisincludedis:
  16. <%
  17. DimHW
  18. FunctionAscAt(s,n)
  19. AscAscAt=Asc(Mid(s,n,1))
  20. EndFunction
  21. FunctionHexAt(s,n)
  22. HexHexAt=Hex(AscAt(s,n))
  23. EndFunction
  24. FunctionisJPG(fichero)
  25. IfinStr(uCase(fichero),".JPG")<>0Then
  26. isJPG=true
  27. Else
  28. isJPG=false
  29. EndIf
  30. EndFunction
  31. FunctionisPNG(fichero)
  32. IfinStr(uCase(fichero),".PNG")<>0Then
  33. isPNG=true
  34. Else
  35. isPNG=false
  36. EndIf
  37. EndFunction
  38. FunctionisGIF(fichero)
  39. IfinStr(uCase(fichero),".GIF")<>0Then
  40. isGIF=true
  41. Else
  42. isGIF=false
  43. EndIf
  44. EndFunction
  45. FunctionisBMP(fichero)
  46. IfinStr(uCase(fichero),".BMP")<>0Then
  47. isBMP=true
  48. Else
  49. isBMP=false
  50. EndIf
  51. EndFunction
  52. FunctionisWMF(fichero)
  53. IfinStr(uCase(fichero),".WMF")<>0Then
  54. isWMF=true
  55. Else
  56. isWMF=false
  57. EndIf
  58. EndFunction
  59. FunctionisWebImg(f)
  60. IfisGIF(f)orisJPG(f)orisPNG(f)orisBMP(f)orisWMF(f)Then
  61. isWebImg=true
  62. Else
  63. isWebImg=true
  64. EndIf
  65. EndFunction
  66. FunctionReadImg(fichero)
  67. IfisGIF(fichero)Then
  68. ReadImg=ReadGIF(fichero)
  69. Else
  70. IfisJPG(fichero)Then
  71. ReadImg=ReadJPG(fichero)
  72. Else
  73. IfisPNG(fichero)Then
  74. ReadImg=ReadPNG(fichero)
  75. Else
  76. IfisBMP(fichero)Then
  77. ReadImg=ReadPNG(fichero)
  78. Else
  79. IfisWMF(fichero)Then
  80. ReadImg=ReadWMF(fichero)
  81. Else
  82. ReadImg=Array(0,0)
  83. EndIf
  84. EndIf
  85. EndIf
  86. EndIf
  87. EndIf
  88. EndFunction
  89. FunctionReadJPG(fichero)
  90. Dimfso,ts,s,HW,nbytes
  91. HW=Array("","")
  92. Setfso=CreateObject("Scripting.FileSystemObject")
  93. Setts=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. EndFunction
  100. FunctionReadPNG(fichero)
  101. Dimfso,ts,s,HW,nbytes
  102. HW=Array("","")
  103. Setfso=CreateObject("Scripting.FileSystemObject")
  104. Setts=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. EndFunction
  111. FunctionReadGIF(fichero)
  112. Dimfso,ts,s,HW,nbytes
  113. HW=Array("","")
  114. Setfso=CreateObject("Scripting.FileSystemObject")
  115. Setts=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. EndFunction
  122. FunctionReadWMF(fichero)
  123. Dimfso,ts,s,HW,nbytes
  124. HW=Array("","")
  125. Setfso=CreateObject("Scripting.FileSystemObject")
  126. Setts=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. EndFunction
  133. FunctionReadBMP(fichero)
  134. Dimfso,ts,s,HW,nbytes
  135. HW=Array("","")
  136. Setfso=CreateObject("Scripting.FileSystemObject")
  137. Setts=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. EndFunction
  144. FunctionisDigit(c)
  145. IfinStr("0123456789",c)<>0Then
  146. isDigit=true
  147. Else
  148. isDigit=false
  149. EndIf
  150. EndFunction
  151. FunctionisHex(c)
  152. IfinStr("0123456789ABCDEFabcdef",c)<>0Then
  153. isHex=true
  154. Else
  155. ishex=false
  156. EndIf
  157. EndFunction
  158. FunctionHexToDec(cadhex)
  159. Dimn,i,ch,decimal
  160. decimal=0
  161. n=Len(cadhex)
  162. Fori=1Ton
  163. ch=Mid(cadhex,i,1)
  164. IfisHex(ch)Then
  165. decimaldecimal=decimal*16
  166. IfisDigit(c)Then
  167. decimaldecimal=decimal+ch
  168. Else
  169. decimaldecimal=decimal+Asc(uCase(ch))-Asc("A")
  170. EndIf
  171. Else
  172. HexToDec=-1
  173. EndIf
  174. Next
  175. HexToDec=decimal
  176. EndFunction
  177. %>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值