ASP图片缩放

 

<%
'------------------------------ GetSize.asp ------------------------------
'File Build Date: 2004-08-14
'ImgPath文件路径,要求绝对路径。ImgWidth图片约束宽度,ImgHeight图片约束高度
'函数返回值为一个5个元素的数组,下面是数组元素返回值的意义
'Array(0):图片类型。只会返回GIF或JPG两种类型,否则就返回空串
'Array(1):约束后的图片宽度
'Array(2):约束后的图片高度
'Array(3):图片原宽度
'Array(4):图片原高度
Function ImgSize(ImgPath,ImgWidth,ImgHeight)
 dim ret(5)
 Set ASO = Server.CreateObject("Adodb.Stream")
 ASO.Mode = 3
 ASO.Type = 1
 ASO.Open
 Set FSO = Server.CreateObject("Scripting.FileSystemObject")
 If Not FSO.FileExists(ImgPath) Then
  Ret(0) = ""
  Ret(1) = 0
  Ret(2) = 0
  Ret(3) = 0
  Ret(4) = 0
  ImgSize = Ret
  Set FSO = Nothing
  FSO  = Empty
  ASO.Close
  Set ASO = Nothing
  ASO = Empty
  Exit Function
 End If
 Set FSO = Nothing
 FSO  = Empty
 ASO.LoadFromFile(ImgPath)
 bFlag=ASO.Read(3)
 If hex(BinVal(bFlag)) = "FFD8FF" Then
  Do
   Do: p1=BinVal(aso.Read(1)): Loop While p1=255 And Not aso.EOS
   If p1>191 And p1<196 Then Exit Do Else aso.Read(BinVal2(aso.Read(2))-2)
   Do:p1=BinVal(aso.Read(1)):Loop While p1<255 And Not aso.EOS
  Loop While true
  aso.Read(3)
  Ret(0) = "JPG"
  Ret(2) = BinVal2(aso.Read(2))
  Ret(1) = BinVal2(aso.Read(2))
  Ret(3) = Ret(1)
  Ret(4) = Ret(2)
 ElseIf Hex(BinVal(bFlag)) = "464947" Then
  aso.Read(3)
  Ret(0) = "GIF"
  Ret(1) = BinVal(aso.Read(2))
  Ret(2) = BinVal(aso.Read(2))
  Ret(3) = Ret(1)
  Ret(4) = Ret(2)
 Else
  Ret(0) = ""
  Ret(1) = 0
  Ret(2) = 0
  Ret(3) = Ret(1)
  Ret(4) = Ret(2)
 End If
 If Ret(0) <> "" Then
  BS = 1
  If IsNumeric(ImgWidth) And IsNumeric(ImgHeight) Then
   If ImgWidth > 0 And ImgHeight > 0 Then
    BS = Ret(1)/ImgWidth
    If BS < Ret(2)/ImgHeight Then BS = Ret(2)/ImgHeight
    If BS < 1 Then BS = 1
   End If
  End If
  Ret(1) = Ret(1)/BS
  Ret(2) = Ret(2)/BS
 End If
 ImgSize = Ret
 ASO.Close
 Set ASO = Nothing
 ASO = Empty
End Function
Private Function BinVal(bin)
 dim ret
 Ret = 0
 For ImgSizeI = lenb(bin) to 1 step -1
  Ret = ret *256 + ascb(midb(bin,ImgSizeI,1))
 Next
 BinVal=ret
End Function
Private Function BinVal2(bin)
 Dim ret
 ret = 0
 For ImgSizeI = 1 To lenb(bin)
 ret = ret *256 + ascb(midb(bin,ImgSizeI,1))
 Next
 BinVal2=ret
End Function
%>

转载于:https://www.cnblogs.com/guo2001china/archive/2011/11/02/2232582.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值