zoukankan      html  css  js  c++  java
  • 献上一款漂亮的手写PHP验证码

    献上一款漂亮的PHP验证码,可以根据个人需求作调整,代码如下(审美观不同,欢迎吐槽):

    <?php
    /**
     *  Author: xiongwei
     *  Email:  695704253@qq.com
     *
     *  注:本代码需要要用到 msyh.ttf 字体,请自行下载
    **/
    
    header("Content-type:image/png");
    
    //图像尺寸
    $width=180;
    $height=70;
    //字体样式
     $font_style='./fontface/msyh.ttf';
    //字体大小
    $font_size=28;
    //干扰点数量
    $noise_num=40;
    //干扰线数量
    $line_num=10;
    
     $expression='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $expression=substr(str_shuffle($expression),0,4);
     
     $img=imagecreatetruecolor($width,$height);
     $bdcolor=imagecolorallocate($img,170,170,170);
     $bgcolor=imagecolorallocate($img,250,250,250);
     
    imagefilledrectangle($img,0,0,$width,$height,$bgcolor);
    imagerectangle($img,0,0,$width-1,$height-1,$bdcolor);
    
    $x=10;
    $y=ceil(($height+$font_size)/2);
    for($i=0;$i<strlen($expression);$i++){
        imagettftext($img,$font_size,mt_rand(-30,30),$x,$y,imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)),$font_style,$expression[$i]);
        $x+=30;
    }
    for($i=0;$i<$noise_num;$i++){
        imagesetpixel($img,mt_rand(1,$width-1),mt_rand(1,$height-1),imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
    }
    for($i=0;$i<$line_num;$i++){
        imagearc($img,mt_rand(-10,0),mt_rand(-10,0),mt_rand(20,400),mt_rand(20,400),50,44,imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
        //imagearc()
    }
    imagepng($img);
    imagedestroy($img); 
    ?>

    效果如下:

  • 相关阅读:
    boost 无锁队列
    boost::asio 的同、异步方式
    MFC获取当前时间
    利用boost获取时间并格式化
    VS2008找不到MFC90d.dll错误解决方法
    boost库在工作(39)网络UDP异步服务端之九
    boost::asio译文
    windows 和linux 同步api对比
    BOOST::Signals2
    redhat 各种版本下载
  • 原文地址:https://www.cnblogs.com/itxiongwei/p/6952351.html
Copyright © 2011-2022 走看看