中文点选验证码之自动识别

某次测验中遇到了汉字点选的验证码,看着很简略,尝试了一下发现有两种简略的识别方法,总算有空给重新整理一下,共享出来。 0×01  验证码的获取 首要获取验证码。因为网站比较特别,就不以他...

某次测验中遇到了汉字点选的验证码,看着很简略,尝试了一下发现有两种简略的识别方法,总算有空给重新整理一下,共享出来。
0×01  验证码的获取
首要获取验证码。因为网站比较特别,就不以他们的为例,自己生成验证码吧。这个不是要点,这儿直接贴代码了。
function createImage($word    ,$imagePath,$type    , $imageName){
   $fontPath = 'msyh.ttc'    ;//字体
   $fontSize = 20     * 0.75;
   foreach ($word     as $v ) {
        $fontarea  =     imagettfbbox($fontSize,     0 , $fontPath, $v        );
        $textWidth =     $fontarea[2] -     $fontarea [0];
        $textHeight =     $fontarea[1] -     $fontarea [7];
        $tmp[    'text'] = $v;
        $tmp[    'size'] = $fontSize;
        $tmp[    'width'] = $textWidth;
        $tmp[    'height'] = $textHeight;
        $textArr[] =     $tmp;
   }
   list( $imageWidth    , $imageHeight,  $imageType) =         getimagesize( $imagePath);
   for( $i    =0;$i list(    $x, $y) =  randPosition        ($textArr,  $imageWidth,             $imageHeight, $textArr[$i                ][ 'width'], $textArr[                    $i]['height'],                    $i,$type);
        $textArr[    $i]['x'] =     $x;
        $textArr[    $i]['y'] =     $y;
   }
   unset( $v    );
   //创立图片的实例
   $image =  imagecreatefromstring    (file_get_contents( $imagePath));
   //字体色彩
   $color =  imagecolorallocate    ($image,  0,         0,  0);
   //绘画文字   
   foreach( $textArr     as $v){
        imagefttext (    $image, $v ['size'        ], 0 , $v[            'x' ], $v['y'                ], $color,  $fontPath                ,$v ['text']);
   }   
   if (imagepng    ( $image,$imageName )){
        echo $imageName    ." n";
   }
}
functionrandPosition ($textArr    ,  $imgW, $imgH ,         $fontW,  $fontH,$i            ,$type){
    switch  ($type    ) {
        case 0    :// 生成mp
             $x =     rand ($i* 60        , ($i +1)*            60-$fontW -            3);   
             $y =     rand (40, 80        );   
             break;
         case1    : //生成ap
             $x = (    $i )*25+ 5        ;
             $y =     25;   

[1] [2] [3] [4]  黑客接单网

  • 发表于 2021-04-09 12:41
  • 阅读 ( 314 )
  • 分类:互联网

0 条评论

请先 登录 后评论
q2296
q2296

742 篇文章

你可能感兴趣的文章

相关问题