1.封装好的图形验证码(挪用注意修改命名空间)
还需要注意修改字体文件位置,更改为你自己放置字体的位置
<?php
namespace app\city\controller;
use think\Controller;
use think\Cookie;
use think\Session;
class Verify extends Controller
{
public function getImgCode(){
ob_clean();
Cookie::set('graphicCode',NULL);
Session::set('graphicCode',NULL);
$code=$this->randStr(4);
Cookie::set('graphicCode',$code);
Session::set('graphicCode',$code);
$x_size=100;
$y_size=40;
//生成图片
$aimg = imagecreate($x_size,$y_size);
//随即图片背景颜色
$back=imagecolorallocate($aimg,rand(200,255),rand(200,255),rand(200,255));
//随机字体颜色
$border=imagecolorallocate($aimg,