码迷,mamicode.com
首页 > Web开发 > 详细

php 实现验证码制作

时间:2015-06-08 14:36:48      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

先给看下 大致的效果

技术分享

那么接下来的就直接贴代码吧

<?php
    
    $image = imagecreatetruecolor(100, 30); //创建画布
    
    $imagecolor = imagecolorallocate($image, 255, 255, 255);  //背景色
    
    imagefill($image, 0, 0, $imagecolor);  //填充背景色
    
    for($i=0;$i<4;$i++ ){                  //循环4位数
        
        $fontsize = 6;
        $fontcolor = imagecolorallocate($image, rand(0, 200), rand(0, 200), rand(0, 200));
        $fontcontent = rand(0, 9);
        
        $x = $i*100/4 + rand(5, 15);
        $y = rand(5, 10);
        
        imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
    }
    
    
    
    for($i=0;$i<200;$i++ ){              //循环 添加干扰点
        
        $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
        
        $x = rand(1, 99);
        $y = rand(1, 29);
        
        imagesetpixel($image, $x, $y, $pointcolor);
    }
    
    
    
    for($i=0;$i<3;$i++){                //循环 添加干扰线    
        
        $linecolor = imagecolorallocate($image, rand(100, 250), rand(100, 250), rand(100, 250));
        
        $x1 = rand(1, 25);
        $x2 = rand(50, 75);
        
        $y1 = rand(1, 15);
        $y2 = rand(15, 25);
        
        imageline($image, $x1, $y1, $x2, $y2, $linecolor);
    }
    
    
    
    header("content-type:image/png");
    
    imagepng($image);
    
    imagedestroy($image);

?>

 

php 实现验证码制作

标签:

原文地址:http://www.cnblogs.com/erbingbing/p/4560663.html

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