<?php
/**
* 生成随机字符串
* @param int $num 生成的随机字符串的个数
* @return str 生成的随机字符串
*/
function randStr($num=6) {
$str = str_shuffle('abcedfghjkmnpqrstuvwxyzABCEDFGHJKMNPQRSTUVWXYZ23456789');
return substr($str, 0 , $num);
}
//1.创建画布
$pic = imagecreatetruecolor(80, 50);
//2.创建颜料(RGB)
$red = imagecolorallocate($pic, 255, 0, 0);
$blue = imagecolorallocate($pic, 127, 127, 127);
//3.背景填充
imagefill($pic, 0, 0, $red);
//4.写入文字
imagestring($pic, 5, 5, 5, randStr(4), $blue);
//5. 输出/保存图形
header('Content-type:image/png');
imagepng($pic);
//6. 销毁画布(关闭画板)
imagedestroy($pic);
?>
008-php生成随机验证码
最新推荐文章于 2021-03-10 20:03:52 发布