百独托管7500 紫田网络超高转化播放器收cps[推荐]速盾CDN 免实名免备防屏蔽阿里云 爆款特卖9.9元封顶提升alexa、IP流量7Q5团队
【腾讯云】中小企福利专场【腾讯云】多款产品1折起高防 随时退换 好耶数据小飞国外网赚带你月入万元炎黄网络4H4G10M 99每月
香港带宽CN2/美国站群优惠中客数据中心 服务器租用联盟系统移动广告平台 中易企业专场腾讯云服务器2.5折九九数据 工信部正规资质
腾讯云新用户大礼包代金券高价收cpa注册量高价展示【腾讯云】2核2G/9.93起租服务器找45互联 随时退换阿里云 短信服务 验证秒达

[落伍原创] [下载][PHP]256色BMP图片验证码识别脚本 [复制链接]
查看:117159 | 回复:19

头像被屏蔽

1

主题

1031

帖子

1739

积分

落伍者(两全齐美)

风之步行者

Rank: 2

贡献
433
鲜花
0
注册时间
2002-2-14
发表于 2005-8-23 02:07:13 | |阅读模式 来自 中国广西南宁
基本说明:

您可以通过本代码片段,了解到:

1.BMP的文件结构,存储方式。
2.对于简单的图像验证码如何进行识别处理。

当然,您也可以使用它完成对一些简单的符合条件的图片验证码进行识别处理。

文件说明:

demo.php 演示脚本
NEATBMP256ValidPic.class.php 相关类脚本
readme.txt 本文件
3721.bmp 3721的图像验证码
csdn.bmp CSDN的图像验证码

demo.php 中已经做了具体的演示。其他部分请自行参考 NEATBMP256ValidPic.class.php 。

联系方式:

walkerlee <walker#neatstudio.com>
http://www.neatcn.com http://www.neatstudio.com


ENJOY! :)

by walkerlee 2005-8-23 1:56

演示地址:http://www.neatstudio.com/validpic/demo.php
下载地址:http://www.neatstudio.com/download/validpic.rar

[ 本帖最后由 walker 于 2005-8-23 02:10 编辑 ]

评分

参与人数 1积分 +20 收起 理由
clinch + 20

查看全部评分

签名被屏蔽
头像被屏蔽

1

主题

1031

帖子

1739

积分

落伍者(两全齐美)

风之步行者

Rank: 2

贡献
433
鲜花
0
注册时间
2002-2-14
 楼主| 发表于 2005-8-23 02:08:02 | 来自 中国广西南宁
下面是具体文件内容

demo.php


  1. <?php

  2. /**
  3. * DEMO for Class NEATBMP256ValidPic
  4. * walkerlee of NEATSTUDIO 2005-8-22
  5. */

  6. // 包含处理类
  7. include_once( 'NEATBMP256ValidPic.class.php' );

  8. // 实例化
  9. $bmp = new NEATBMP256ValidPic;

  10. // 设置文件
  11. $bmp->SetFile( '3721.bmp' );

  12. $bmp->SetCodeColor( array( 1 ) );
  13. $bmp->SetFrontColor( '#FFFFFF' );
  14. $bmp->SetBackColor( '#3399CC' );

  15. // 打开位图文件
  16. $bmp->Open();

  17. ///////////////////////////////////////////////////////////////////////////////
  18. // 例一 绘制位图数据偏移坐标图 ( 存储模式 )

  19. /**
  20. * 绘制位图数据偏移坐标图
  21. * 因为BMP存储数据时候,是把图像反着存储的,所以看到的是一个倒着的图像.
  22. */
  23. echo "<p>例一 : 存储模式 ( 一般用于寻找数据偏移位置 ) </p>";
  24. $bmp->Draw();

  25. ///////////////////////////////////////////////////////////////////////////////
  26. // 例二 绘制位图数据偏移坐标图 ( 观察模式 )

  27. // 现在我们用查看模式来重新读取一次数据
  28. $bmp->GetData( 'pop' );

  29. /**
  30. * 这时候绘制出的数据偏移坐标图则是我们用眼睛所观察到的正置的图像.
  31. */
  32. echo "<p>例二 : 观察模式 ( 一般用于观察 )</p>";
  33. $bmp->Draw();

  34. ///////////////////////////////////////////////////////////////////////////////
  35. // 例三 绘制位图数据偏移坐标图 ( 颜色代码模式 )

  36. // 设置绘图方式为颜色代码显示方式
  37. $bmp->SetDrawMod( 'source' );

  38. // 绘制
  39. echo "<p>例三 : 颜色代码模式 ( 一般用于寻找验证码颜色 ) </p>";
  40. $bmp->Draw();

  41. ///////////////////////////////////////////////////////////////////////////////
  42. // 例四 识别3721验证码 ( 通过逐一设置参数的方式 )

  43. // 码表
  44. $N3721_CODE[0] = "00011000001111000110011011000011110000111100001111000011011001100011110000011000";
  45. $N3721_CODE[1] = "00011000001110000111100000011000000110000001100000011000000110000001100001111110";
  46. $N3721_CODE[2] = "00111100011001101100001100000011000001100000110000011000001100000110000011111111";
  47. $N3721_CODE[3] = "01111100110001100000001100000110000111000000011000000011000000111100011001111100";
  48. $N3721_CODE[4] = "00000110000011100001111000110110011001101100011011111111000001100000011000000110";
  49. $N3721_CODE[5] = "11111110110000001100000011011100111001100000001100000011110000110110011000111100";
  50. $N3721_CODE[6] = "00111100011001101100001011000000110111001110011011000011110000110110011000111100";
  51. $N3721_CODE[7] = "11111111000000110000001100000110000011000001100000110000011000001100000011000000";
  52. $N3721_CODE[8] = "00111100011001101100001101100110001111000110011011000011110000110110011000111100";
  53. $N3721_CODE[9] = "00111100011001101100001111000011011001110011101100000011010000110110011000111100";

  54. // 设置验证码颜色,可以是多个颜色
  55. $bmp->SetCodeColor( array( 1 ) );

  56. // 设置验证码字串数目
  57. $bmp->SetCodeTotal( 5 );

  58. // 设置验证码字符宽度
  59. $bmp->SetFontWeight( 8 );

  60. // 设置验证码字符高度
  61. $bmp->SetFontHeight( 10 );

  62. // 设置验证码字符间隔距离
  63. $bmp->SetFontSpace( 1 );

  64. // 设置第一个验证字符的左上数据偏移
  65. $bmp->SetOffSet( 3188 );

  66. // 设置对比用码表
  67. $bmp->SetCollateCode( $N3721_CODE );

  68. // 识别处理
  69. $code = $bmp->Valid();

  70. echo "<p>例四 识别3721验证码 ( 通过逐一设置参数的方式 )</p>";
  71. echo "<img src='3721.bmp'> 识别结果:" . $code;

  72. // 关闭文件
  73. $bmp->Close();

  74. ///////////////////////////////////////////////////////////////////////////////
  75. // 例五 识别CSDN验证码 ( 通过装载配置参数的方式 )

  76. // 相关参数
  77. $CSDN_CODE[0] = "001111000100001010000001100000011000000110000001100000011000000110000001100000010100001000111100";
  78. $CSDN_CODE[1] = "000010000000100000111000000010000000100000001000000010000000100000001000000010000000100000111110";
  79. $CSDN_CODE[2] = "001111000100001000000001000000010000000100000010000001000000100000010000001000000100000001111111";
  80. $CSDN_CODE[3] = "001111000100001000000001000000010000001000011100000000100000000100000001000000010100001000111100";
  81. $CSDN_CODE[4] = "000000100000011000001010000100100010001001000010100000101111111100000010000000100000001000000010";
  82. $CSDN_CODE[5] = "011111110100000001000000010000000111110000000010000000010000000100000001000000010100001000111100";
  83. $CSDN_CODE[6] = "000111100010000001000000100000001011110011000010100000011000000110000001100000010100001000111100";
  84. $CSDN_CODE[7] = "011111110000000100000010000000100000010000000100000010000000100000010000000100000010000000100000";
  85. $CSDN_CODE[8] = "001111000100001010000001100000010100001000111100010000101000000110000001100000010100001000111100";
  86. $CSDN_CODE[9] = "001111000100001010000001100000011000000110000001010000110011110100000001000000100000010001111000";

  87. $CSDN = array(

  88.         'CodeColor'                => array( 45 ),
  89.         'CodeTotal'                => 4,
  90.         'FontWeight'                => 8,
  91.         'FontHeight'                => 12,
  92.         'FontSpace'                => 1,
  93.         'OffSet'                                => 1601,
  94.         'CollateCode'                => $CSDN_CODE,

  95. );

  96. // 设置文件
  97. $bmp->SetFile( 'csdn.bmp' );

  98. // 装载参数
  99. $bmp->LoadConfig( $CSDN );

  100. // 把数据初始化
  101. $bmp->Init();

  102. // 打开位图文件
  103. $bmp->Open();

  104. // 识别处理
  105. $code = $bmp->Valid();

  106. // 关闭文件
  107. $bmp->Close();

  108. echo "<p>例五 识别CSDN验证码 ( 通过装载配置参数的方式 )</p>";
  109. echo "<img src='csdn.bmp'> 识别结果:" . $code;

  110. ?>
复制代码
签名被屏蔽
头像被屏蔽

1

主题

1031

帖子

1739

积分

落伍者(两全齐美)

风之步行者

Rank: 2

贡献
433
鲜花
0
注册时间
2002-2-14
 楼主| 发表于 2005-8-23 02:08:35 | 来自 中国广西南宁
NEATBMP256ValidPic.class.php


  1. <?php

  2. /*
  3. * 本代码思路基于 NetDust <oy_@163.net> 的文章 “程序识别验证码图片” .
  4. * 由NEATSTUDIO ( http://www.neatstudio.com ) 的 walkerlee <walker@neatstudio.com>用PHP重新描述, 并改进成半通用版本.
  5. * 本代码片段遵循GPL许可协议发布. 您可以任意修改和传播本代码片段,但请保留我们的版权信息.
  6. */

  7. /**
  8. * 256色BMP图片校验码识别类
  9. * Created / Modify : 2005-8-21 / 2005-8-22
  10. * @name  NEATBMP256ValidPic
  11. * @version  1.0.0
  12. * @author  walkerlee <walker@neatstudio.com>
  13. * @copyright  Powered by NEATSTUDIO 2002 - 2005 <neatstudio@qq.com>
  14. * @link http://www.neatstudio.com NeatStudio
  15. * @package NEATFramework
  16. * @subpackage NEATImage
  17. */

  18. /**
  19. * TODO :
  20. * 异常处理,比如,在处理前先判断图片是否是BMP格式。并且是256色。
  21. */

  22. class NEATBMP256ValidPic
  23. {
  24.        
  25.         /**
  26.         * 待处理文件的绝对或者相对路径
  27.         * @var string
  28.         * @access private
  29.         */
  30.         var $bmpFile = '';

  31.         /**
  32.         * 前景色
  33.         * @var string
  34.         * @access private
  35.         */
  36.         var $frontColor = '#3399CC';

  37.         /**
  38.         * 背景色
  39.         * @var string
  40.         * @access private
  41.         */
  42.         var $backColor = '#FFFFFF';

  43.         /**
  44.         * 验证码颜色
  45.         * @var integer
  46.         * @access private
  47.         */
  48.         var $codeColor = '';

  49.         /**
  50.         * 表格绘图模式
  51.         * @var string
  52.         * @access private
  53.         */
  54.         var $drawMod = '';

  55.         /**
  56.         * 字体宽度
  57.         * @var integer
  58.         * @access private
  59.         */
  60.         var $fontWeight = '';

  61.         /**
  62.         * 字体高度
  63.         * @var integer
  64.         * @access private
  65.         */
  66.         var $fontHeight = '';

  67.         /**
  68.         * 字间距离
  69.         * @var integer
  70.         * @access private
  71.         */
  72.         var $fontSpace = '';

  73.         /**
  74.         * 待识别验证码字符个数
  75.         * @var integer
  76.         * @access private
  77.         */
  78.         var $codeTotal = '';

  79.         /**
  80.         * 第一个数字的左上角的数据偏移
  81.         * @var integer
  82.         * @access private
  83.         */
  84.         var $offSet = '';

  85.         /**
  86.         * 对比码数组
  87.         * @var array
  88.         * @access private
  89.         */
  90.         var $collateCode = array();

  91.         //////////////////////////////////////////////////////////////////////////////

  92.         /**
  93.         * 图片信息数组
  94.         * @var array
  95.         * @access private
  96.         */
  97.         var $imageInfo = array();


  98.         /**
  99.         * 原始图像数据数组
  100.         * @var array
  101.         * @access private
  102.         */
  103.         var $buffer = array();

  104.         /**
  105.         * 图片数据数组
  106.         * @var array
  107.         * @access private
  108.         */
  109.         var $imgData = array();

  110.         //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  111.         // communications function
  112.         //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  113.        
  114.         /**
  115.         * 设置待处理的文件
  116.         * @param string $file 文件绝对或者相对路径
  117.         * @access public
  118.         */
  119.         function SetFile( $file )
  120.         {
  121.                 $this->bmpFile = $file;
  122.         }

  123.         /**
  124.         * 设置前景色
  125.         * @param string $color 前景色 用于在表格上显示 16位格式 例:#FF0000
  126.         * @access public
  127.         */
  128.         function SetFrontColor( $color )
  129.         {
  130.                 $this->frontColor = $color;
  131.         }

  132.         /**
  133.         * 设置背景色
  134.         * @param string $color 背景色 用于在表格上显示 16位格式 例:#FF0000
  135.         * @access public
  136.         */
  137.         function SetBackColor( $color )
  138.         {
  139.                 $this->backColor = $color;
  140.         }
  141.        
  142.         /**
  143.         * 设置验证码颜色
  144.         * @param string $color 验证码颜色 验证码的着色 范围在0-255
  145.         * @access public
  146.         */
  147.         function SetCodeColor( $color )
  148.         {
  149.                 $this->codeColor = $color;
  150.         }

  151.         /**
  152.         * 设置表格绘图模式
  153.         * @param string $mod 绘图模式 source 是直接显示出当前像素的颜色代码 0-255
  154.         * @access public
  155.         */
  156.         function SetDrawMod( $mod )
  157.         {
  158.                 $this->drawMod = $mod;
  159.         }

  160.         /**
  161.         * 设置字体宽度
  162.         * @param integer $weight 字体宽度 以像素为单位
  163.         * @access public
  164.         */
  165.         function SetFontWeight( $weight )
  166.         {
  167.                 $this->fontWeight = $weight;
  168.         }

  169.         /**
  170.         * 设置字体高度
  171.         * @param integer $height 字体高度 以像素为单位
  172.         * @access public
  173.         */
  174.         function SetFontHeight( $height )
  175.         {
  176.                 $this->fontHeight = $height;
  177.         }

  178.         /**
  179.         * 设置字间距离
  180.         * @param integer $space 字间距离 以像素为单位
  181.         * @access public
  182.         */
  183.         function SetFontSpace( $space )
  184.         {
  185.                 $this->fontSpace = $space;
  186.         }

  187.         /**
  188.         * 设置待识别的验证码字符个数
  189.         * @param integer $total 字符个数
  190.         * @access public
  191.         */
  192.         function SetCodeTotal( $total )
  193.         {
  194.                 $this->codeTotal = $total;
  195.         }

  196.         /**
  197.         * 设置第一个数字的左上角的数据偏移
  198.         * @param integer $offset 偏移位置
  199.         * @access public
  200.         */
  201.         function SetOffSet( $offset )
  202.         {
  203.                 $this->offSet = $offset;
  204.         }

  205.         /**
  206.         * 设置对比码
  207.         * @param array $code 对比码数组
  208.         * @access public
  209.         */
  210.         function SetCollateCode( $code )
  211.         {
  212.                 $this->collateCode = $code;
  213.         }

  214.         //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  215.         // common operation function
  216.         //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  217.         /**
  218.         * 打开文件
  219.         * @return boolean
  220.         * @access public
  221.         */
  222.         function Open()
  223.         {
  224.                 return $this->fp = fopen( $this->bmpFile, "rb" );
  225.         }

  226.         /**
  227.         * 关闭文件
  228.         * @return boolean
  229.         * @access public
  230.         */
  231.         function Close()
  232.         {
  233.                 return fclose( $this->fp );
  234.         }

  235.         /**
  236.         * 读取配置参数
  237.         * @param array $config 配置参数数组
  238.         * @access public
  239.         */
  240.         function LoadConfig( $config )
  241.         {
  242.                 $this->codeColor        = $config['CodeColor'];
  243.                 $this->codeTotal        = $config['CodeTotal'        ];
  244.                 $this->fontWeight        = $config['FontWeight'];
  245.                 $this->fontHeight        = $config['FontHeight'];
  246.                 $this->fontSpace        = $config['FontSpace'];
  247.                 $this->offSet                        = $config['OffSet'];
  248.                 $this->collateCode = $config['CollateCode'];
  249.         }


  250.         /**
  251.         * 返回已经获取的图片信息
  252.         * @return array 图片信息数组
  253.         * @access public
  254.         */
  255.         function GetInfo()
  256.         {
  257.                 return $this->imageInfo;
  258.         }

  259.         /**
  260.         * 获取原始的图片内容
  261.         * @return array 原始图片内容数组
  262.         * @access public
  263.         */
  264.         function GetBaseData()
  265.         {               
  266.                 // 如果 $this->imageInfo 不存在 : 读取图片信息
  267.                 if ( !$this->imageInfo )
  268.                         $this->Info();
  269.                
  270.                 // 逐行读取
  271.                 for ( $i = $this->imageInfo['Height'] - 1; $i >= 0; $i-- )
  272.                 {
  273.                         // 计算出数据偏移
  274.                         $pos = $this->imageInfo['Offset'] + ( $this->imageInfo['Height'] - $i - 1 ) * $this->imageInfo['Weight'];
  275.                        
  276.                         // 移动指针
  277.                         fseek ( $this->fp, $pos );

  278.                         // 计算本行数据偏移
  279.                         $line = $i * $this->imageInfo['Weight'];

  280.                         // 初始化数组
  281.                         $arr = array();

  282.                         // 逐列读取
  283.                         for ( $k = 0; $k < $this->imageInfo['Weight'] ; $k++ )
  284.                         {
  285.                                 // 读取当前像素点的颜色数值,保存进本列数组
  286.                                 $arr[] = $this->_Bin2asc( fread( $this->fp, 1 ) );
  287.                         }

  288.                         // 构造数组
  289.                         $this->buffer[$line] = $arr;
  290.                 }

  291.                 return $this->buffer;
  292.         }

  293.         /**
  294.         * 获取图片内容
  295.         * @param string $order 参数:shift 原始存储模式 图片是反着存储的。用于寻找第一个字符的数据偏移 参数:pop 显示模式 用于显示。
  296.         * @return array 图片内容数组
  297.         * @see GetBaseData
  298.         * @access public
  299.         */
  300.         function GetData( $order = 'shift' )
  301.         {
  302.                
  303.                 // 如果 $this->buffer 不存在 : 获取图片原始内容
  304.                 if ( !$this->buffer )
  305.                         $this->GetBaseData();

  306.                 // 判断数据构造模式
  307.                 if ( $order == 'shift' )
  308.                         $handleMod = 'array_shift'; // 存储模式 图像倒置
  309.                 else
  310.                         $handleMod = 'array_pop'; // 显示模式 图像正置
  311.                
  312.                 // 获取原始图片内容数组的行数
  313.                 $arrayNum = count( $this->buffer );

  314.                 // 逐行处理
  315.                 for( $i = 1; $i <= $arrayNum; $i++ )
  316.                 {
  317.                         // 重建数组
  318.                         $this->imgData[$i] = $handleMod( $this->buffer );
  319.                 }

  320.                 return $this->imgData;
  321.         }

  322. /**
  323.         * 取得图片信息
  324.         * @return array 图片信息数组
  325.         * @access public
  326.         */
  327.         function Info()
  328.         {
  329.                 // 读取图片格式
  330.                 $this->imageInfo['Type'] = fread( $this->fp, 2 );

  331.                 // 读取图片尺寸
  332.                 $this->imageInfo['Size'] = $this->_ReadInt();

  333.                 // 保留地址
  334.                 $this->imageInfo['Reserved'] = $this->_ReadInt();

  335.                 // 获取数据偏移
  336.                 $this->imageInfo['Offset'] = $this->_ReadInt();

  337.                 // 获取头信息
  338.                 $this->imageInfo['Header'] = dechex( $this->_ReadInt() ) . 'H';

  339.                 // 获取图片的宽度
  340.                 $this->imageInfo['Weight'] =  $this->_ReadInt();

  341.                 // 获取图片的高度
  342.                 $this->imageInfo['Height'] =  $this->_ReadInt();

  343.                 // 获取图片的位面数
  344.                 $this->imageInfo['Planes'] =  $this->_Bin2asc( fread( $this->fp, 2 ) );

  345.                 // 获取图片的每个象素的位数
  346.                 $this->imageInfo['Bits Per Pixel'] =  $this->_Bin2asc( fread( $this->fp, 2 ) );

  347.                 // 获取图片的压缩说明
  348.                 $this->imageInfo['Compression'] =  $this->_ReadInt();

  349.                 // 用字节数表示的位图数据的大小。该数必须是4的倍数
  350.                 $this->imageInfo['Bitmap Data Size'] =  $this->_ReadInt();

  351.                 // 用象素/米表示的水平分辨率
  352.                 $this->imageInfo['HResolution'] =  $this->_ReadInt();

  353.                 // 用象素/米表示的垂直分辨率
  354.                 $this->imageInfo['VResolution'] =  $this->_ReadInt();

  355.                 // 位图使用的颜色数。如8-比特/象素表示为100h或者 256.
  356.                 $this->imageInfo['Colors'] =  $this->_ReadInt();

  357.                 // 指定重要的颜色数。当该域的值等于颜色数时(或者等于0时),表示所有颜色都一样重要
  358.                 $this->imageInfo['Important Colors'] =  $this->_ReadInt();
  359.         }

  360.         /**
  361.         * 绘出坐标表
  362.         * @access public
  363.         */
  364.         function Draw()
  365.         {
  366.                 // 如果 $this->imgData 不存在 : 获取图片内容
  367.                 if ( !$this->imgData )
  368.                         $this->GetData();
  369.                
  370.                 // 显示表格以及样式
  371.                 echo "<table border=1 style="border-collapse: collapse;font-size : 8pt; font-family : 'verdana'">";
  372.                 echo "<tr align=center><td bgcolor='#EFEFEF'>&nbsp;</td><td bgcolor='#EFEFEF'>&nbsp;</td>";
  373.                 // 显示顶部坐标
  374.                 for( $i = 1; $i <= $this->imageInfo['Weight']; $i++ )
  375.                         echo "<td height='10' bgcolor='#EFEFEF'>" . sprintf( '%02.0f', $i ) . "</td>";
  376.                 echo "<td bgcolor='#EFEFEF'>&nbsp;</td></tr>";
  377.                
  378.                 // 逐行绘制表格
  379.                 for( $I = 1; $I <= count( $this->imgData ); $I++ )
  380.                 {
  381.                         // 获取本行数据
  382.                         $line = $this->imgData[$I];

  383.                         // 显示本行数据偏移
  384.                         echo "<tr align=center><td height=10><font color=#CC3366>" . ( ( $I - 1 ) * $this->imageInfo['Weight'] ) . "</font></td><td bgcolor='#EFEFEF'>" . sprintf( '%02.0f', $I ) . "</td>";

  385.                         // 逐一绘制表格
  386.                         for ( $i = 0; $i < count( $line ); $i++ )
  387.                         {
  388.                                 // 获取当前像素点的颜色数值
  389.                                 $data = $line[$i];

  390.                                 // 判断绘制模式
  391.                                 if ( $this->drawMod == 'source' ) // 原始数据模式
  392.                                         echo "<td>" . $data . "</td>";
  393.                                 else // 观察模式
  394.                                 {
  395.                                         // 如果本像素点颜色是校验码颜色 设置本表格颜色为前景色
  396.                                         if ( in_array( $data, $this->codeColor ) )
  397.                                                 $color = $this->frontColor;
  398.                                         else // 如果本像素点颜色不是校验码颜色 设置本表格颜色为背景色
  399.                                                 $color = $this->backColor;

  400.                                         // 获取当前像素的数据偏移
  401.                                         $pos = ( $I - 1 ) * $this->imageInfo['Weight'] + $i + 1;

  402.                                         // 显示表格
  403.                                         echo "<td bgcolor=" . $color . " title='" . $pos . "'></td>";
  404.                                 }
  405.                         }
  406.                         echo "<td bgcolor='#EFEFEF'>" . sprintf( '%02.0f', $I ) . "</td></tr>";
  407.                 }

  408.                 echo "<tr align=center><td bgcolor='#EFEFEF'>&nbsp;</td><td bgcolor='#EFEFEF'>&nbsp;</td>";
  409.                 // 显示底部坐标
  410.                 for( $i = 1; $i <= $this->imageInfo['Weight']; $i++ )
  411.                         echo "<td height='10' bgcolor='#EFEFEF'>" . sprintf( '%02.0f', $i ) . "</td>";
  412.                 echo "<td bgcolor='#EFEFEF'>&nbsp;</td></tr>";

  413.                 echo "</table>";
  414.         }

  415.         /**
  416.         * 识别位图
  417.         * @return string 识别后的字串
  418.         * @access public
  419.         */
  420.         function Valid()
  421.         {
  422.                 // 如果 $this->imgData 不存在 : 获取图片内容
  423.                 if ( !$this->imgData )
  424.                         $this->GetData();
  425.                
  426.                 // 根据校验码个数逐一识别
  427.                 for ( $i = 0; $i < $this->codeTotal; $i++)
  428.                 {
  429.                         // 计算数字左上数据偏移
  430.                         $bp = $this->offSet + ( $this->fontWeight + $this->fontSpace ) * $i;

  431.                         // 获取对比特征码
  432.                         $tmp = $this->_GetBound( $bp );

  433.                         // 设置当前字符默认识别结果 * 代表无法识别
  434.                         $c = '*';

  435.                         // 遍历对比码,检查匹配情况
  436.                         foreach ( $this->collateCode as $k => $v )
  437.                         {
  438.                                 // 匹配
  439.                                 if ( $tmp === $v )
  440.                                 {
  441.                                         // 设置当前字符识别结果
  442.                                         $c = $k;
  443.                                         break;
  444.                                 }
  445.                         }

  446.                         // 组合结果
  447.                         $rs .= $c;
  448.                 }
  449.                 return $rs;
  450.         }

  451.         /**
  452.         * 初始化数据状态
  453.         * @access public
  454.         */
  455.         function Init()
  456.         {
  457.                 $this->imageInfo = array();
  458.                 $this->buffer = array();
  459.                 $this->imgData = array();
  460.         }

  461.         //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  462.         // private function
  463.         //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  464.         /**
  465.         * 读取INT
  466.         * @return integer 数字
  467.         * @access private
  468.         */
  469.         function _ReadInt()
  470.         {
  471.            return $this->_Bin2asc( fread ( $this->fp, 4 ) );
  472.         }

  473.         /**
  474.         * 二进制转ASCII
  475.         * @return string 转换后的内容
  476.         * @access private
  477.         */
  478.         function _Bin2asc ( $binary )
  479.         {
  480.                 $val = 0;
  481.                 for ($i = strlen( $binary ) - 1; $i >= 0; $i--)
  482.                 {
  483.                    $ch = substr( $binary, $i, 1 );
  484.                    $val = ( $val << 8 ) | ord( $ch );
  485.            }
  486.            return $val;
  487.         }

  488.         /**
  489.         * 获取数据区域特征码
  490.         * @return string 特征码
  491.         * @access private
  492.         */
  493.         function _GetBound( $bp )
  494.         {
  495.                 // 移动指针
  496.                 fseek( $this->fp, $bp );

  497.                 // 按照矩形图形从左到右、从上到下的方向进行提取
  498.                 for ( $i = 1; $i <= $this->fontHeight; $i++  )
  499.                 {
  500.                         for ( $ii = 1; $ii <= $this->fontWeight; $ii++ )
  501.                         {
  502.                                 // 获取当前像素点颜色数值
  503.                                 $data = $this->_Bin2asc( fread( $this->fp, 1 ) );

  504.                                 // 如该像素颜色数值和校验码颜色匹配则表示为1, 否则为0
  505.                                 if (  in_array( $data, $this->codeColor ) )
  506.                                         $rs .= 1;
  507.                                 else
  508.                                         $rs .= 0;
  509.                         }

  510.                         // 指针移动到下一校验码区域
  511.                         fseek( $this->fp, $bp - $i * $this->imageInfo['Weight'] );
  512.                 }

  513.                 return $rs;
  514.         }
  515. }
  516. ?>
复制代码
签名被屏蔽
头像被屏蔽

1

主题

2269

帖子

2345

积分

落伍者(两全齐美)

GG他爷爷

Rank: 2

贡献
0
鲜花
0
注册时间
2004-4-8
发表于 2005-8-23 02:37:10 | 来自 中国上海
支持~~~~一记~
签名被屏蔽
头像被屏蔽

3

主题

2万

帖子

2万

积分

禁言

禁止发炎

贡献
19
鲜花
4
注册时间
2002-6-29
发表于 2005-8-23 03:07:09 | 来自 中国江苏南京
对我没啥用处```````
签名被屏蔽

131

主题

2万

帖子

2054

积分

落伍者(两全齐美)

资深民工/总捅

Rank: 2

贡献
676
鲜花
31
注册时间
2002-11-21
发表于 2005-8-23 07:42:51 | 来自 中国上海
哇靠,不加分不加精没天理啊
头像被屏蔽

0

主题

1万

帖子

1万

积分

落伍者(四季发财)

接VC++(软件)和PHP(网站)的活 ...

Rank: 4

贡献
0
鲜花
0
注册时间
2002-12-1
发表于 2005-8-23 08:28:41 | 来自 中国山东济南
就是就是,楼主的代码一向严整,很佩服楼主。
签名被屏蔽

852

主题

1万

帖子

1万

积分

落伍者(四季发财)

Rank: 4

贡献
1025
鲜花
396
注册时间
2005-6-23
发表于 2005-8-23 09:01:00 | 来自 中国山东济南
支持啊
济南做网站
凯式定氮仪  脂肪测定仪
www.alrva.com www.biaofan.com.cn www.zgmlg.com

164

主题

2万

帖子

1万

积分

落伍斑竹

dfsdfdsafa

Rank: 8Rank: 8

贡献
64
鲜花
69
注册时间
2003-11-10
发表于 2005-8-23 10:55:25 | 来自 中国广东汕头
我服务器从昨天晚上挂到现在,郁闷啊,少了n多ip
流量太大了,把内存吃光了
落伍禁止黄赌毒签名违规签名,请注意规则,违规永禁。
头像被屏蔽

2

主题

5237

帖子

5880

积分

落伍者(三羊开泰)

不懂技术

Rank: 3Rank: 3

贡献
0
鲜花
6
注册时间
2004-5-28

落伍美化

发表于 2005-8-23 17:45:24 | 来自 中国广西桂林
楼主的一定要UP
签名被屏蔽
论坛客服/商务合作/投诉举报:2171544 (QQ)
落伍者创建于2001/03/14,本站内容均为会员发表,并不代表落伍立场!
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!
落伍官方微信:2030286 邮箱:(djfsys@gmail.com|tech@im286.com)
© 2001-2014

浙公网安备 33060302000191号

浙ICP备11034705号 BBS专项电子公告通信管[2010]226号

  落伍法律顾问: ITlaw-庄毅雄

手机版|找回帐号|不能发帖?|Archiver|落伍者

GMT+8, 2024-5-23 09:44 , Processed in 0.133832 second(s), 42 queries , Gzip On.

返回顶部