利用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

相关文章

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

Python获取C++中返回的char*字段的两种思路

《Python获取C++中返回的char*字段的两种思路》有时候需要获取C++函数中返回来的不定长的char*字符串,本文小编为大家找到了两种解决问题的思路,感兴趣的小伙伴可以跟随小编一起学习一下... 有时候需要获取C++函数中返回来的不定长的char*字符串,目前我找到两种解决问题的思路,具体实现如下:

golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法

《golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法》:本文主要介绍golang获取当前时间、时间戳和时间字符串及它们之间的相互转换,本文通过实例代码给大家介绍的非常详细,感兴趣... 目录1、获取当前时间2、获取当前时间戳3、获取当前时间的字符串格式4、它们之间的相互转化上篇文章给大家介

Feign Client超时时间设置不生效的解决方法

《FeignClient超时时间设置不生效的解决方法》这篇文章主要为大家详细介绍了FeignClient超时时间设置不生效的原因与解决方法,具有一定的的参考价值,希望对大家有一定的帮助... 在使用Feign Client时,可以通过两种方式来设置超时时间:1.针对整个Feign Client设置超时时间

详解C++中类的大小决定因数

《详解C++中类的大小决定因数》类的大小受多个因素影响,主要包括成员变量、对齐方式、继承关系、虚函数表等,下面就来介绍一下,具有一定的参考价值,感兴趣的可以了解一下... 目录1. 非静态数据成员示例:2. 数据对齐(Padding)示例:3. 虚函数(vtable 指针)示例:4. 继承普通继承虚继承5.

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片