为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

1 回答

<?php
$width = 300;
$height = 100;
$image =imagecreatetruecolor($width,$height); //创建画布

$white = imagecolorallocate($image,255,255,255);//画布背景色

imagefilledrectangle($image,0,0,$width,$height,$white); //填充画布背景色


for($i=0;$i<4;$i++){
    $fontsize = mt_rand(30,40);
    $fontcolor=imagecolorallocate($image,rand(0, 120),rand(0, 120),rand(0, 120));
    //验证码颜色,放在循环里,每个字符颜色不同
    $data = "abcdefghijklmnpqrstuvwyz123456789";
    $fontcontent = substr($data,rand(0, strlen($data)-1), 1);

    $x=($i*300/4)+rand(30, 50);

    $y=rand(40, 70);

    $angle = mt_rand(-15,15);

    imagettftext($image,$fontsize,$angle,$x,$y,$fontcolor,'msyh.ttc',$fontcontent);
}
header("content-type:image/jpeg;charset=utf-8");

ob_clean(); //这个就很怪,有时候不加就报错

imagejpeg($image);

imagedestroy($image);


?>

欢迎采纳

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求完整验证码代码

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信