利用ASP获取设置图片尺寸大小

2024-04-21 02:18

本文主要是介绍利用ASP获取设置图片尺寸大小,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

< %
imgpath
= " default_22.gif "

response.write 
" <img src=' " & imgpath & " ' border=0  " & SetAutoImg( 280 , 260 ,imgpath) & " ><br>宽: " & GetImgW(ImgPath) & " ;高: " & GetImgH(ImgPath)
function  GetImgW(ImgPath)
    
set  pp = new  imgInfo 
    w
= pp.imgW(server.mappath(ImgPath)) 
    
set  pp = nothing  
    GetImgW
= w
end function

function  GetImgH(ImgPath)
    
set  pp = new  imgInfo 
    h
= pp.imgH(server.mappath(ImgPath)) 
    
set  pp = nothing  
    GetImgH
= h
end function

function  SetAutoImg(fitWidth,fitHeight,ImgPath)
    hhRtn
= 0
    wwRtn
= 0
    
set  pp = new  imgInfo 
    ww
= pp.imgW(server.mappath(ImgPath)) 
    hh
= pp.imgH(server.mappath(ImgPath))     
    
set  pp = nothing  
    
if  ww > 0   and  hh > 0   then
        
if  ww / hh >= FitWidth / FitHeight  then
            wwRtn
= fitWidth
            hhRtn
= (hh * FitWidth) / ww
        
else
            hhRtn
= fitHeight
            wwRtn
= (ww * FitHeight) / hh
        
end   if
    
end   if
    SetAutoImg
= "  height=' " & hhRtn & " ' " & "  width=' " & wwRtn & " "
end function

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
%
>

这篇关于利用ASP获取设置图片尺寸大小的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/921928

相关文章

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

C# foreach 循环中获取索引的实现方式

《C#foreach循环中获取索引的实现方式》:本文主要介绍C#foreach循环中获取索引的实现方式,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、手动维护索引变量二、LINQ Select + 元组解构三、扩展方法封装索引四、使用 for 循环替代

Linux下如何使用C++获取硬件信息

《Linux下如何使用C++获取硬件信息》这篇文章主要为大家详细介绍了如何使用C++实现获取CPU,主板,磁盘,BIOS信息等硬件信息,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录方法获取CPU信息:读取"/proc/cpuinfo"文件获取磁盘信息:读取"/proc/diskstats"文

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

SpringMVC获取请求参数的方法

《SpringMVC获取请求参数的方法》:本文主要介绍SpringMVC获取请求参数的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下... 目录1、通过ServletAPI获取2、通过控制器方法的形参获取请求参数3、@RequestParam4、@

C#TextBox设置提示文本方式(SetHintText)

《C#TextBox设置提示文本方式(SetHintText)》:本文主要介绍C#TextBox设置提示文本方式(SetHintText),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录C#TextBox设置提示文本效果展示核心代码总结C#TextBox设置提示文本效果展示核心代

Pyserial设置缓冲区大小失败的问题解决

《Pyserial设置缓冲区大小失败的问题解决》本文主要介绍了Pyserial设置缓冲区大小失败的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录问题描述原因分析解决方案问题描述使用set_buffer_size()设置缓冲区大小后,buf