<?php// 丢弃输出缓冲区的内容 **ob_clean();
// 创建画布$image = imagecreatetruecolor(110, 30);
// 设置白色底$bgColor = imagecolorallocate($image, 255, 255, 255);imagefill($image, 0, 0, $bgColor);
// 添加四个随机数字字母for($i=0;$i<4;$i++) { $fontSize = 6; // 随机分配颜色 $fontColor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120)); // 生成内容 $data = "abcdefghijkmnpqrstuvwxy3456789"; // 如果内容为空,重新输出1个 do { $fontCont = substr($data, rand(0, strlen($data)), 1); } while ($fontCont == ''); // 设置范围 $x = ($i*110/4)+rand(5, 10); $y = rand(5, 10); // 图片加入数字 imagestring($image, $fontSize, $x, $y, $fontCont, $fontColor);}
// 添加干扰点元素for($j=0;$j<200;$j++) { // 点颜色 $pointColor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200)); imagesetpixel($image, rand(1, 99), rand(1, 29), $pointColor);}
// 添加干扰线元素for($z=0;$z<4;$z++) { // 生成颜色线 $lineColor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220)); imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $lineColor);}
header("Content-type:image/png");// 输出图片imagepng($image);// 销毁内存中的图片imagedestroy($image);
?>
评论