电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> Asp>>ASP实现图片等比例缩放函数代码:imgInfo:

ASP实现图片等比例缩放函数代码:imgInfo

来源:网络 | 2007-4-18 | (有4115人读过)

’========================== 
’Define Class imgInfo  
’========================== 
Class imgInfo  
dim aso  
Private Sub Class_Initialize  
set aso=CreateObject("Adodb.Stream")  
aso.Mode=3  
aso.Type=1  
aso.Open  
End Sub  
Private Sub Class_Terminate 
’err.clear 
set aso=nothing  
End Sub  

Private Function Bin2Str(Bin)  
Dim I, Str  
For I=1 to LenB(Bin)  
clow=MidB(Bin,I,1)  
if ASCB(clow)<128 then  
Str = Str & Chr(ASCB(clow))  
else  
I=I+1  
if I <= LenB(Bin) then Str = Str & Chr(ASCW(MidB(Bin,I,1)&clow))  
end if  
Next  
Bin2Str = Str  
End Function  

Private Function Num2Str(num,base,lens)  
dim ret  
ret = ""  
while(num>=base)  
ret = (num mod base) & ret  
num = (num - num mod base)/base  
wend  
Num2Str = right(string(lens,"0") & num & ret,lens)  
End Function  

Private Function Str2Num(str,base)  
dim ret  
ret = 0  
for i=1 to len(str)  
ret = ret *base + cint(mid(str,i,1))  
next  
Str2Num=ret  
End Function  

Private Function BinVal(bin)  
dim ret  
ret = 0  
for i = lenb(bin) to 1 step -1  
ret = ret *256 + ascb(midb(bin,i,1))  
next  
BinVal=ret  
End Function  

Private Function BinVal2(bin)  
dim ret  
ret = 0  
for i = 1 to lenb(bin)  
ret = ret *256 + ascb(midb(bin,i,1))  
next  
BinVal2=ret  
End Function  

Private Function getImageSize(filespec)  
dim ret(3)  
aso.LoadFromFile(filespec)  
bFlag=aso.read(3)  
select case hex(binVal(bFlag))  
case "4E5089":  
aso.read(15)  
ret(0)="PNG"  
ret(1)=BinVal2(aso.read(2))  
aso.read(2)  
ret(2)=BinVal2(aso.read(2))  
case "464947":  
aso.read(3)  
ret(0)="GIF"  
ret(1)=BinVal(aso.read(2))  
ret(2)=BinVal(aso.read(2))  
case "535746":  
aso.read(5)  
binData=aso.Read(1)  
sConv=Num2Str(ascb(binData),2 ,8)  
nBits=Str2Num(left(sConv,5),2)  
sConv=mid(sConv,6)  
while(len(sConv)<nBits*4)  
binData=aso.Read(1)  
sConv=sConv&Num2Str(ascb(binData),2 ,8)  
wend  
ret(0)="SWF"  
ret(1)=int(abs(Str2Num(mid(sConv,1*nBits+1,nBits),2)-Str2Num(mid(sConv,0*nBits+1,nBits),2))/20)  
ret(2)=int(abs(Str2Num(mid(sConv,3*nBits+1,nBits),2)-Str2Num(mid(sConv,2*nBits+1,nBits),2))/20)  
case "FFD8FF":  
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))  
case else:  
if left(Bin2Str(bFlag),2)="BM" then  
aso.Read(15)  
ret(0)="BMP"  
ret(1)=binval(aso.Read(4))  
ret(2)=binval(aso.Read(4))  
else  
ret(0)=""  
end if  
end select  
ret(3)="width=""" & ret(1) &""" height=""" & ret(2) &""""  
getimagesize=ret  
End Function  

Public Function imgW(pic_path)  
Set fso1 = server.CreateObject("Scripting.FileSystemObject")  
If (fso1.FileExists(pic_path)) Then  
Set f1 = fso1.GetFile(pic_path)  
ext=fso1.GetExtensionName(pic_path)  
select case ext  
case "gif","bmp","jpg","png":  
arr=getImageSize(f1.path)  
imgW = arr(1)  
end select  
Set f1=nothing  
else 
imgW = 0 
End if  
Set fso1=nothing  
End Function  

Public Function imgH(pic_path)  
Set fso1 = server.CreateObject("Scripting.FileSystemObject")  
If (fso1.FileExists(pic_path)) Then  
Set f1 = fso1.GetFile(pic_path)  
ext=fso1.GetExtensionName(pic_path)  
select case ext  
case "gif","bmp","jpg","png":  
arr=getImageSize(f1.path)  
imgH = arr(2)  
end select  
Set f1=nothing  
else 
imgH = 0  
End if  
Set fso1=nothing  
End Function  
End Class 
’======================== 
’end of class 
’======================== 

sub ArticleContent(intTitleLen) 
      dim i,strTemp,w,f ’add w.h 
      i=0 
set    pp=new    imgInfo    ’add get pic ’s width and length 
do while not rsArticle.eof 
    strTemp=""   
    strTemp= strTemp & "<table width=100% border=0 cellspacing=3 cellpadding=0>" 
                  strTemp= strTemp & "<tr>" 
          dim i1 
         for i1=1 to 4 
                   strTemp= strTemp & "<td width=25% valign=bottom><table width=100% border=0 cellspacing=0 cellpadding=0>" 
                   strTemp= strTemp & "<tr>" 
       
          strTemp= strTemp & "<td><div align=center><a href=ProductShow.asp?ArticleID=" & rsArticle("articleid") & ">"  
     
      fileExt=lcase(getFileExtName(rsArticle("DefaultPicUrl"))) 
      if fileext="jpg" or fileext="bmp" or fileext="png" or fileext="gif" then 
           
       w = 125 /(pp.imgW(server.mappath(rsArticle("DefaultPicUrl"))))     图片的高宽比 
       f = (pp.imgH(server.mappath(rsArticle("DefaultPicUrl")))) * w         得到高度 
      
      
                   strTemp= strTemp & "<img border=0 src=" & rsArticle("DefaultPicUrl") & " alt="&rsArticle("bigclassname")&"&#10"&rsArticle("title")&" height="& f &" width=125 >"  
      else 
       if fileext="swf" then 
          strTemp= strTemp & "<object    classid=’clsid:D27CDB6E-AE6D-11cf-96B8-444553540000’    codebase=’http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0’ width=’105’ height=’84’>" 
       strTemp= strTemp &"<param name=movie value=’"&rsArticle("DefaultPicUrl")&"’>" 
       strTemp= strTemp &"<param name=quality value=high>" 
       strTemp= strTemp &"<param name=’Play’ value=’-1’>" 
       strTemp= strTemp &"<param name=’Loop’ value=’0’>" 
       strTemp= strTemp &"<param name=’Menu’ value=’-1’>" 
       strTemp= strTemp &"<param name=’wmode’ value=’transparent’>" 
       strTemp= strTemp &"<embed src=’"&rsArticle("DefaultPicUrl")&"’ width=’105’ height=’84’ pluginspage=’http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash’ type=’application/x-shockwave-flash’></embed> </object>"             
        end if 
          end if     
      
                   strTemp= strTemp & "</a></div></td>" 
        

                     strTemp= strTemp & "<tr>" 
       
               
                   strTemp= strTemp & "<td align=center>" 
                   strTemp= strTemp & "<a href=ProductShow.asp?ArticleID=" & rsArticle("articleid") & ">" & rsArticle("Title") & "" 
                   strTemp= strTemp & "</a></td>" 
          strTemp= strTemp & "</tr>"  
                   strTemp= strTemp & "</table>" 
                   strTemp= strTemp & "</td>" 

                rsArticle.movenext 
          if rsArticle.eof then 
           strTemp= strTemp & "</tr></table>"   
           response.write strTemp 
     exit do 
          end if 
         next 

         rsArticle.moveprevious 

         strTemp= strTemp & "</tr></table>"   
         response.write strTemp 
         rsArticle.movenext 
         i=i+1 
         if i>=(MaxPerPage/4) then exit do  
loop 
end sub  
Asp热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号