php生成数字字母的验证码图片

yipeiwu_com5年前PHP代码库

php生成数字字母的验证码图片

<?php

header ('Content-Type: image/png');
$image=imagecreatetruecolor(100, 30);
$color=imagecolorallocate($image, 255, 255, 255);
imagefill($image, 20, 20, $color);
//只含有数字
// for($i=0;$i<4;$i++){
  // $font=6;
  // $x=rand(5,10)+$i*100/4;
  // $y=rand(8, 15);
  // $string=rand(0, 9);
  // $color=imagecolorallocate($image, rand(0,120), rand(0,120), rand(0,120));
  // imagestring($image, $font, $x, $y, $string, $color);
// }

//含有数字和字母的
for($i=0;$i<4;$i++){
  $fontSize=6;
  $x=rand(5,10)+$i*100/4;
  $y=rand(5, 15);
  $data='abcdefghijklmnopqrstuvwxyz123456789';
  $string=substr($data,rand(0, strlen($data)),1);
  $color=imagecolorallocate($image,rand(0,120), rand(0,120), rand(0,120));
  imagestring($image, $fontSize, $x, $y, $string, $color);
}
//干扰点元素
for($i=0;$i<200;$i++){
  $pointColor=imagecolorallocate($image, rand(100, 255), rand(100, 255), rand(100, 255));
  imagesetpixel($image, rand(0, 100), rand(0, 30), $pointColor);
}
//干扰线元素
for($i=0;$i<2;$i++){
  $linePoint=imagecolorallocate($image, rand(150, 255), rand(150, 255), rand(150, 255));
  imageline($image, rand(10, 50), rand(10, 20), rand(80,90), rand(15, 25), $linePoint);
}
imagepng($image);
imagedestroy($image);
?>

以上所述就是本文的全部内容了,希望大家能够喜欢。

相关文章

php实现简单的守护进程创建、开启与关闭操作

本文实例讲述了php实现简单的守护进程创建、开启与关闭操作。分享给大家供大家参考,具体如下: 前提要安装有pcntl扩展,可通过php -m查看是否安装 <?php c...

redis查看连接数及php模拟并发创建redis连接的方法

max_redis.php <?php set_time_limit (0); for($i=1;$i<=1050;$i++){ exec("nohup p...

详解PHP序列化和反序列化原理

0.前言 对象的序列化和反序列化作用就不再赘述,php中序列化的结果是一个php自定义的字符串格式,有点类似json. 我们在任何语言中设计对象的序列化和反序列化都需要解决几个问题 把某...

简单谈谈PHP中的Reload操作

前言 有很多前辈告诫过我们,reload 能保证整个过程的平滑性,所谓平滑性指的是在 reload 的过程中,旧的进程在处理完当前请求前不会提前终止。很多年来,我从来没有质疑过这种说法,...

PHP基于单例模式编写PDO类的方法

一、单例模式简介 简单的说,一个对象(在学习设计模式之前,需要比较了解面向对象思想)只负责一个特定的任务; 二、为什么要使用PHP单例模式?    &n...