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

相关文章

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下

SpringBoot 获取请求参数的常用注解及用法

《SpringBoot获取请求参数的常用注解及用法》SpringBoot通过@RequestParam、@PathVariable等注解支持从HTTP请求中获取参数,涵盖查询、路径、请求体、头、C... 目录SpringBoot 提供了多种注解来方便地从 HTTP 请求中获取参数以下是主要的注解及其用法:1

SQL Server 查询数据库及数据文件大小的方法

《SQLServer查询数据库及数据文件大小的方法》文章介绍了查询数据库大小的SQL方法及存储过程实现,涵盖当前数据库、所有数据库的总大小及文件明细,本文结合实例代码给大家介绍的非常详细,感兴趣的... 目录1. 直接使用SQL1.1 查询当前数据库大小1.2 查询所有数据库的大小1.3 查询每个数据库的详

MySQL设置密码复杂度策略的完整步骤(附代码示例)

《MySQL设置密码复杂度策略的完整步骤(附代码示例)》MySQL密码策略还可能包括密码复杂度的检查,如是否要求密码包含大写字母、小写字母、数字和特殊字符等,:本文主要介绍MySQL设置密码复杂度... 目录前言1. 使用 validate_password 插件1.1 启用 validate_passwo

在ASP.NET项目中如何使用C#生成二维码

《在ASP.NET项目中如何使用C#生成二维码》二维码(QRCode)已广泛应用于网址分享,支付链接等场景,本文将以ASP.NET为示例,演示如何实现输入文本/URL,生成二维码,在线显示与下载的完整... 目录创建前端页面(Index.cshtml)后端二维码生成逻辑(Index.cshtml.cs)总结

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

Python获取浏览器Cookies的四种方式小结

《Python获取浏览器Cookies的四种方式小结》在进行Web应用程序测试和开发时,获取浏览器Cookies是一项重要任务,本文我们介绍四种用Python获取浏览器Cookies的方式,具有一定的... 目录什么是 Cookie?1.使用Selenium库获取浏览器Cookies2.使用浏览器开发者工具

Java获取当前时间String类型和Date类型方式

《Java获取当前时间String类型和Date类型方式》:本文主要介绍Java获取当前时间String类型和Date类型方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录Java获取当前时间String和Date类型String类型和Date类型输出结果总结Java获取

C#监听txt文档获取新数据方式

《C#监听txt文档获取新数据方式》文章介绍通过监听txt文件获取最新数据,并实现开机自启动、禁用窗口关闭按钮、阻止Ctrl+C中断及防止程序退出等功能,代码整合于主函数中,供参考学习... 目录前言一、监听txt文档增加数据二、其他功能1. 设置开机自启动2. 禁止控制台窗口关闭按钮3. 阻止Ctrl +

Go语言编译环境设置教程

《Go语言编译环境设置教程》Go语言支持高并发(goroutine)、自动垃圾回收,编译为跨平台二进制文件,云原生兼容且社区活跃,开发便捷,内置测试与vet工具辅助检测错误,依赖模块化管理,提升开发效... 目录Go语言优势下载 Go  配置编译环境配置 GOPROXYIDE 设置(VS Code)一些基本