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

yipeiwu_com6年前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 Coding Tips(php小技巧)[2011/04/02最后更新]

最后更新: 2011/04/02 1. 使用list来实现一次获取explode后的特定段值: list( , $mid) = explode(';', $string); 2. 使用N...

PHP实现的简单适配器模式示例

本文实例讲述了PHP实现的简单适配器模式。分享给大家供大家参考,具体如下: <?php //适配器模式-通过适配器去执行第三方方法 //定义目标接口 interface...

WordPress中给文章添加自定义字段及后台编辑功能区域

WordPress中给文章添加自定义字段及后台编辑功能区域

add_post_meta add_post_meta 函数是 WordPress 中用来给文章或页面添加自定义字段值的一个函数, 其用法与在编写文章时在文章编写界面中利用自定义栏目面...

PHP实现SMTP邮件的发送实例

当你还在纠结php内置的mail()函数不能发送邮件时,那么你现在很幸运,此时的这篇文章可以帮助到你! php利用smtp类来发邮件真是屡试不爽,我用过很久了,基本上没出过问题。本博客后...

PHP中去除换行解决办法小结(PHP_EOL)

第一种写法: $content=str_replace("\n","",$content); echo $content; 第二种写法: str_replace("\r\n","",$s...