码迷,mamicode.com
首页 > 其他好文 > 详细

验证码

时间:2016-11-21 22:49:36      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:pix   bst   fill   color   zab   ges   创建   str   oca   

/*
    步骤:
        1.创建画布
        2.造颜料
        3.填充背景颜色
        4.画干扰点
        5.画噪点
        6.写字符串
        7.输出图片
        8.销毁画布
     */
    //1.创建画布
    $im=imagecreatetruecolor(50, 30);

    //2.造颜料
    $gray = imagecolorallocate($im,30,30,30);
    $red = imagecolorallocate($im,255,0,0);
    $blue = imagecolorallocate($im, 100, 255, 255);

    //3.填充背景颜色  
    imagefill($im,0,0,$blue);

    //4.画干扰点
    for ($i=0; $i <4 ; $i++) { 
         imageline($im, rand(0,20),0,100,rand(0,60),$red);
    }

    //5.画噪点   
        for($i=0;$i<100;$i++){   
            imagesetpixel($im,rand(0,50),rand(0,30),$gray);   
        } 

    //6.写字符串
    $str=substr(str_shuffle(‘ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789‘),0,4);
    imagestring($im,5,5,5,$str,$red);
    
    //7.输出图片   
        header(‘content-type:image/png‘);   
        imagepng($im); 

        //8.销毁画布
        imagedestroy($im);

  

验证码

标签:pix   bst   fill   color   zab   ges   创建   str   oca   

原文地址:http://www.cnblogs.com/Czc963239044/p/6087202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!