// 在画板上画点,美高梅赌堵59599:复制代码 代码如下

2020-03-21 作者:联系我们   |   浏览(140)

<?php
/*
* Created on 2011-7-31
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
for($i=0;$i<4;$i++){
     $rand.=rand(1,9);
}
$b=imagecreate(130,40卡塔尔;//建个图像
imagecolorallocate($b,0,0,0卡塔尔国;//设置图像颜色
$color=imagecolorallocate($b,255,255,255卡塔尔国;//设置图像字体颜色
for($i=0;$i<3;$i++){
    $color2=imagecolorallocate($b,rand(0,255卡塔尔国,rand(0,255State of Qatar,rand(0,255State of Qatar卡塔尔国;//设置图像随机颜色

for($i=0;$i<5;$i++){

上边是法力图,那么些职能图是没有展开烦闷码的意义图
美高梅赌堵59599 1
下边是类代码

<?php
/*img.php
 * Created on 2009-2-9
 * Created by yunqing
 * yunqing's personal page:remindme.blogbus.com
 * yunqing's QQ:493568395
 * yunqing's Email:syq1357@qq.com
 */
    session_start();
    for($i=1;$i<=4;$i++){
         $rand.=dechex(rand(1,15));
    }
    $_SESSION['check_img']=$rand;
     $img=imagecreatetruecolor(100,30);
     imagecolorallocate($img,0,0,0);
     $color=imagecolorallocate($img,255,255,255);
     imagestring($img,rand(1,6),rand(3,70),rand(1,20),$rand,$color);
     header("Content-type:image/jpeg"State of Qatar;//告诉浏览器输出的格式,近日浏览器的功能                                                                 //较苍劲,可粗略
     imagejpeg($img);
?>

    $b2=imageline($b,rand(0,100卡塔尔国,0,rand(0,255State of Qatar,40,$color2卡塔尔国;//设置一个验证码线段
}
for($i=0;$i<200;$i++){
    imagesetpixel($b,rand(卡塔尔(قطر‎%130,rand(卡塔尔(قطر‎%40,$color2State of Qatar;//设置验证码的点
}
imagestring($b,4,12,12,$rand,$color卡塔尔国;//将字体写如图像中
header("content-type:image/gif");
imagegif($b卡塔尔国;//输出这一个图像

    $rand .= dechex(rand(1,15));  // 随机数16进制 1-F 生成5个

复制代码 代码如下:
/************************************************
//FILE:ImageCode
//DONE:生成动态验证码类
//DATE"2010-3-31
//Author:www.5dkx.com 5D欢愉博客
************************************************************************/
class ImageCode{
private $width; //验证码图片宽度
private $height; //验证码图片高度
private $codeNum; //验证码字符个数
private $checkCode; //验证码字符
private $image; //验证码画布
/************************************************************************
// Function:布局函数
// Done:成员属性起头化
// Author:www.5dkx.com 5D快乐博客
************************************************************************/
function __construct($width=60,$height=20,$codeNum=4)
{
$this->width = $width;
$this->height = $height;
$this->codeNum = $codeNum;
$this->checkCode = $this->createCheckCode();
}
function showImage()
{
$this->getcreateImage();
$this->outputText();
$this->setDisturbColor();
$this->outputImage();
}
function getCheckCode()
{
return $this->chekCode;
}
private function getCreateImage()
{
$this->image = imagecreatetruecolor($this->width,$this->height);
$back = imagecolorallocate($this->image,255,255,255);
$border = imagecolorallocate($this->image,255,255,255);
imagefilledrectangle($this->image,0,0,$this->width-1,$this->height-1,$border);
//使用纯莲红填充矩形框,这里用的话前边郁闷码失效
/*万一想用烦扰码的话使用上边包车型客车*/
//imagerectangle($this->image,0,0,$this->width-1,$this->height-1,$border);
}
private function createCheckCode()
{
for($i=0;$icodeNum;$i++)
{
$number = rand(0,2);
switch($number)
{
case 0: $rand_number = rand(48,57); break;//数字
case 1: $rand_number = rand(65,90State of Qatar;break;//大写字母
case 2: $rand_number = rand(97,122卡塔尔;break;//小写字母
}
$asc = sprintf("%c",$rand_number);
$asc_number = $asc_number.$asc;
}
return $asc_number;
}
private function setDisturbColor(卡塔尔国//烦扰吗设置
{
for($i=0;$i<=100;$i++)
{
//$color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));
$color = imagecolorallocate($this->image,255,255,255);
imagesetpixel($this->image,rand(1,$this->width-2),rand(1,$this->height-2),$color);
}
//$color = imagecolorallocate($this->image,0,0,0);
//imagesetpixel($this->image,rand(1,$this->width-2),rand(1,$this->height-2),$color);
}
private function outputText()
{
//随机颜色、随机摆放、随机字符串向图像输出
for($i=0;$i<=$this->codeNum;$i++)
{
$bg_color = imagecolorallocate($this->image,rand(0,255),rand(0,128),rand(0,255));
$x = floor($this->width/$this->codeNum)*$i+3;
$y = rand(0,$this->height-15);
imagechar($this->image,5,$x,$y,$this->checkCode[$i],$bg_color);
}
}
private function outputImage()
{
if(imagetypes()&IMG_GIF)
{
header("Content_type:image/gif");
imagegif($this->image);
}
elseif(imagetypes()&IMG_JPG)
{
header("Content-type:image/jpeg");
imagejpeg($this->image,"",0.5);
}
elseif(imagetypes()&IMG_PNG)
{
header("Content-type:image/png");
imagejpeg($this->image);
}
elseif(imagetypes()&IMG_WBMP)
{
header("Content-type:image/vnd.wap.wbmp");
imagejpeg($this->image);
}
else
{
die("PHP不援救图像创制"卡塔尔国;
}
}
function __destruct()
{
imagedestroy($this->image);
}
}
/*显示*/
/*******************************************************************
session_start();
$image = new ImageCode(60,20,4);
$image->showImage();
$_SESSION['ImageCode'] = $image->getCheckCode();
*******************************************************************/
?>

<?php
/*check.php
 * Created on 2009-2-9
 * Created by yunqing
 * yunqing's personal page:remindme.blogbus.com
 * yunqing's QQ:493568395
 * yunqing's Email:syq1357@qq.com
 */
 session_start();
if($_POST['check']){
    if($_POST['check']==$_SESSION['check_img']){
        echo "验证码准确".$_SESSION['check_img']."
";
        echo "<a href='check.php'>重新填写</a>";
    }else{
        echo "验证码错误".$_SESSION['check_img']."
";
        echo "<a href='check.php'>重新填写</a>";
    }
}else{
?>
  <form action="" method="post">
  <img src='img.php'>

?>

}

  <input type="text" name="check">

 

  <input type="submit" name="sub" value="提交"/>
  </form>

 

<?php }?>

上面是改进过的能够突显汉语验证码跟噪点的表明图片生成文书:
<?php
/*img.php
 * Created on 2009-2-9
 * Created by yunqing
 * yunqing's personal page:remindme.blogbus.com
 * yunqing's QQ:493568395
 * yunqing's Email:syq1357@qq.com
 */
    //打开SESSION
    session_start();
    //随机生成4个数字字母
    for($i=1;$i<=4;$i++){
         $rand.=dechex(rand(1,15));
    }
    //将转变的数字存入SESSION
    $_SESSION['check_img']=$rand;
    //生成四个图形画板
     $img=imagecreatetruecolor(100,30);
     //第一遍颜色调制作为画板背景象
     imagecolorallocate($img,0,0,0);
     //调制暗蓝
     $white=imagecolorallocate($img,255,255,255);
     //调制随机色
     $color=imagecolorallocate($img,rand(1,255),rand(1,255),rand(1,255));
     //随机生成4条直线
     for($i=0;$i<4;$i++){
     imageline($img,0,0,rand(0,100),30,$color);
     imageline($img,100,30,rand(0,100),0,$color);
     }
     //随机生成200个点
     for($i=0;$i<200;$i++){
     imagesetpixel($img,rand(0,100),rand(0,30),$color);
     }
//     imagestring($img,rand(1,6State of Qatar,rand(3,70卡塔尔(قطر‎,rand(1,20State of Qatar,$rand,$white卡塔尔;//随机数字
                                                                    //字母展现
     //中文展现
     $icon=iconv('gbk','utf-8',"元宵节欢喜"State of Qatar;
     imagettftext($img,12,0,rand(0,45),rand(10,30),$white,"simhei.ttf",$icon);
     //告诉浏览器什么格式
     header("Content-type:image/jpeg");
     //将PHP生成的二进制编码转变来图像编码
     imagejpeg($img);

$im = imagecreatetruecolor(100,30卡塔尔(قطر‎;      // 验证码的朗朗上口(画板)

本文由美高梅赌堵59599发布于联系我们,转载请注明出处:// 在画板上画点,美高梅赌堵59599:复制代码 代码如下

关键词: