源码网,源码论坛,源码之家,商业源码,游戏源码下载,discuz插件,棋牌源码下载,精品源码论坛

 找回密码
 立即注册
查看: 442|回复: 14

[ASP编程] asp正则html的图片,对图自动缩放大小

[复制链接]

7万

主题

861

回帖

32万

积分

论坛元老

Rank: 8Rank: 8

积分
329525
发表于 2008-3-6 10:19:14 | 显示全部楼层 |阅读模式
下面的代码是从html中正则取出图片,然后批量替换等 下面这个是比较不错的一个
复制代码 代码如下:
Function FormatImg2(content) 
           dim re
           Set re=new RegExp
           re.IgnoreCase =true
           re.Global=True
           re.Pattern="(script)"
           Content=re.Replace(Content,"script")
           re.Pattern="<img.[^>]*src(=| )(.[^>]*)>"
         Content=re.replace(Content,"<img src=$2  style=""cursor: pointer"" alt=""点此在新窗口浏览图片"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
          set re = nothing
          FormatImg = content
        end function

上面有点不好的就是对于图片中的宽度和高度都不存在了
复制代码 代码如下:
Function getphoto(strHTML) 
Dim objRegExp, Match, Matches 
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True 
objRegExp.Global = True 
objRegExp.Pattern = "<img.+?>" 
tp=""
Set Matches = objRegExp.Execute(strHTML)
For Each Match in Matches 
tp=tp & Match.value 
exit for
Next 
getphoto=tp
Set objRegExp = Nothing 
End Function

下面的代码时进行图片按比例缩放
复制代码 代码如下:
function ResizeImage(imageid,limitWidth,limitHeight) 
{     
    var image = new Image(); 
    image.src = imageid.src; 

    if(image.width <= 0 && image.height <= 0) return; 

    if(image.width/image.height >= limitWidth/limitHeight) 
    { 
        if(image.width > limitWidth) 
        { 
            imageid.width = limitWidth; 
            imageid.height = (image.height*limitWidth)/image.width; 
        } 
    } 
    else if(image.height > limitHeight) 
    { 
            imageid.height = limitHeight; 
            imageid.width = (image.width*limitHeight)/image.height;      
    } 

    if (imageid.parentElement.tagName != "A") 
    { 
        imageid.onclick = function(){window.open(this.src);} 
        imageid.style.cursor = "hand"; 
    } 


window.onload = InitImages;
function InitImages() 

//图片的约束宽度和高度
   var maxWidth = 100; 
    var maxHeight = 100; 
    var imgs = document.getElementsByTagName("img"); 
    for(var i=0; i < imgs.length; i++) 
    { 
        var img = imgs; 
        if(img.width>maxWidth||img.height>maxHeight) 
            ResizeImage(img, maxWidth, maxHeight); 
    } 
}
回复

使用道具 举报

7

主题

1万

回帖

398

积分

中级会员

Rank: 3Rank: 3

积分
398
发表于 2022-8-8 10:53:47 | 显示全部楼层
来看看!!!
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2022-8-9 05:54:03 | 显示全部楼层
人都不在了啊 啊
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2022-12-10 21:54:56 | 显示全部楼层
人都不在了啊 啊
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2023-1-10 01:26:11 | 显示全部楼层
可以,看卡巴
回复 支持 反对

使用道具 举报

27

主题

1万

回帖

331

积分

中级会员

Rank: 3Rank: 3

积分
331
发表于 2023-1-18 00:39:28 | 显示全部楼层
不错的源码论坛
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2023-6-11 14:17:52 | 显示全部楼层
看看看咋么
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2023-10-18 21:18:43 | 显示全部楼层
问问问企鹅哇哇哇哇哇
回复 支持 反对

使用道具 举报

4

主题

1万

回帖

58

积分

注册会员

Rank: 2

积分
58
发表于 2023-11-11 16:14:21 | 显示全部楼层
借款金额看了就立刻
回复 支持 反对

使用道具 举报

0

主题

1万

回帖

0

积分

中级会员

Rank: 3Rank: 3

积分
0
发表于 2024-3-2 05:12:35 | 显示全部楼层
看到这帖子真是高兴!
回复 支持 反对

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

手机版|小黑屋|网站地图|源码论坛 ( 海外版 )

GMT+8, 2024-9-21 03:36 , Processed in 0.159545 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表