欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP把网页中的电话号码生成图片的代码

程序员文章站 2022-05-17 15:38:42
作用:将页面中的电话号码生成图片格式。 <%call com_creatvalidcode(request.querystring...

作用:将页面中的电话号码生成图片格式。

<%
call com_creatvalidcode(request.querystring("tel"))

public sub com_creatvalidcode(ptel)

     ----------禁止缓存
     response.expires = 0
     response.addheader "pragma","no-cache"
     response.addheader "cache-ctrol","no-cache"
     response.contenttype = "image/bmp"

     randomize

     dim i, ii, iii ,rndcolor,strlen,sql,rs

     const codds = 5 ------------杂点出现的机率
     const str="0123456789-"
     strlen = len(ptel)
     rndcolor = chrb(cint(rnd*255)) & chrb(cint(rnd*255)) & chrb(cint(rnd*255))

     -----------颜色的数据(字符,背景)
     dim vcolordata(1)

     vcolordata(0) = chrb(0) & chrb(0) & chrb(0)     ----蓝0,绿0,红0(黑色)
     vcolordata(1) = chrb(255) & chrb(255) & chrb(255) ----蓝250,绿236,红211(浅蓝色)

     vcolordata(0) = chrb(197) & chrb(106) & chrb(49)     ---- 蓝0,绿0,红0(黑色)
     vcolordata(1) = chrb(238) & chrb(210) & chrb(193) -----蓝250,绿236,红211(浅蓝色)

     vcolordata(0) = chrb(0) & chrb(0) & chrb(0)     ---------蓝0,绿0,红0(黑色)
     vcolordata(1) = chrb(205) & chrb(237) & chrb(245) ------------蓝250,绿236,红211(浅蓝色)


     --------------------随机产生字符
     randomize

     dim vcode()
     redim vcode(strlen-1)
     for i = 0 to strlen-1
         vcode(i) =instr(1,str,mid(ptel,i+1,1),1)-1
     next


     -----------字符的数据
     dim vnumberdata(11)

     verdana font
     vnumberdata(0) = "11111111111000111101110111011101110111011101110111011101110111011110001111111111"
     vnumberdata(1) = "11111111111101111110011111110111111101111111011111110111111101111110001111111111"
     vnumberdata(2) = "11111111111000111101110111011101111110111111011111101111110111111100000111111111"
     vnumberdata(3) = "11111111111000111101110111111101111100111111110111111101110111011110001111111111"
     vnumberdata(4) = "11111111111110111111001111101011111010111101101111100001111110111111100111111111"
     vnumberdata(5) = "11111111110000011101111111011111110000111111110111111101110111011110001111111111"
     vnumberdata(6) = "11111111111000111101101111011111110000111101110111011101110111011110001111111111"
     vnumberdata(7) = "11111111110000011101101111111011111101111111011111110111111101111111011111111111"
     vnumberdata(8) = "11111111111000111101110111011101111000111101110111011101110111011110001111111111"
     vnumberdata(9) = "11111111111000111101110111011101110111011110000111111101111011011110000111111111"
     vnumberdata(10) = "11111111111111111111111111111111111111111100000111111111111111111111111111111111"
     vnumberdata(11) = "11111111111111111111111111111111111111111111111111111111111111111111111111111111"

     -----------------输出图像文件头 <br>
     response.binarywrite chrb(66) & chrb(77) &chrb(((strlen*8*10*3+54) mod 256)) & chrb(((strlen*8*10*3+54) 256)mod 256) & chrb((((strlen*8*10*3+54) 256)256)mod 256) & chrb(((((strlen*8*10*3+54) 256)256)256)mod 256) & chrb(0) & chrb(0) &_
     chrb(0) & chrb(0) & chrb(54) & chrb(0) & chrb(0) & chrb(0) & chrb(40) & chrb(0) &_
     chrb(0) & chrb(0) & chrb(strlen*8) & chrb(0) & chrb(0) & chrb(0) & chrb(10) & chrb(0) &_
     chrb(0) & chrb(0) & chrb(1) & chrb(0)

     ------------------输出图像信息头
     response.binarywrite chrb(24) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0)&_
     chrb((strlen*8*10*3)mod 256)&chrb(((strlen*8*10*3)256)mod 256)&chrb((((strlen*8*10*3)256)256)mod 256)&chrb(((((strlen*8*10*3)256)256)256)mod 256)&_
     chrb(196) & chrb(14) & chrb(0) & chrb(0) & chrb(196) & chrb(14)&chrb(0) & chrb(0) &_
      chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0)

     for i = 9 to 0 step -1     ----------历经所有行
         for ii = 0 to strlen-1     -------历经所有字
             for iii = 1 to 8 --------历经所有像素
                ---------逐行、逐字、逐像素地输出图像数据
                if rnd * 99 + 1 < codds then ---------随机生成杂点
                     response.binarywrite rndcolor
                else
                     response.binarywrite vcolordata(mid(vnumberdata(vcode(ii)), i * 8 + iii, 1))
                end if
             next
         next
     next
end sub
%>

将以上代码保存为img.,在要显示电话号码的位置插入<img src="img.asp?tel=0591-26728373">即可