<?php
header('Content-type:
image/png');
/**
* Created by coder meng.
* User: coder meng
* Date: 2016/4/9 16:05
*/
// 1.创建画布
$width=100;
$height=30;
$im=imagecreatetruecolor($width,$height);
//2.设置颜色
$red=imagecolorallocate($im,255,0,0);
$green=imagecolorallocate($im,0,255,0);
$blue=imagecolorallocate($im,0,0,255);
$white=imagecolorallocate($im,192,220,192);
$color=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
//3.填充颜色
imagefill($im,0,0,$white);
for($i=0;$i<100;$i++)
{
//画点
imagesetpixel($im,rand(0,$width),rand(0,$height),$color);
//画线
}
for($j=0;$j<10;$j++)
{
imageline($im,rand(0,$width),rand(0,$height),rand(0,$width),rand(0,$height),$color);
}
$text=rand(1000,9999);
// Replace path by your own font path
$font='consola.ttf';
// Add some shadow to the text
imagettftext($im,20,0,11,21,$color,$font,$text);
imagepng($im);
//5关闭资源
imagedestroy($im);
PHP图片验证码
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 前言:这篇文章里面的代码是基于spring boot的,直接拷贝可用,可以先用了再去理解里面原理1.请求获取验证码...