PHP生成验证码背景的干扰点
效果图如下:每一次刷新的效果都会不同
<?php
//画布大小
$width =60;
$height=25;
//图片句柄
$image = imagecreate($width, $height);
//背景颜色
$image_bgcolor = imagecolorallocate($image, 255, 255, 255);
//$边框颜色
$image_bolorcolor = imagecolorallocate($image, 0, 0, 0);
//绘制边框
imagerectangle($image, 0, 0, $width-1, $height-1, $image_bolorcolor);
//设置干扰点个数
$num_distrub_points =200;
for ($i = 0; $i < $num_distrub_points; $i++) {
//随机设置干扰点颜色
$point_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
//干扰点的位置
$point_x = rand(2, $width-2);
$point_y = rand(2, $height-2);
//绘制干扰点
imagesetpixel($image, $point_x, $point_y, $point_color);
}
header("content-type:image/png");
imagepng($image);
imagedestroy($image);
?>
页:
[1]