在 PHP 中使用 GD 库创建带有圆形图案的图像

create an image with circle pattern with GD library in PHP

this question 中有一个优秀的代码,它使用 PHP GD 库生成类似于以下示例的图像。图像基本上是重复的square pattern

我需要创建与 circles pattern 相似的图像,但我无法这样做,因为我仍在学习。我尝试使用 imagefilledellipse.

修改代码
$width = 1000; 
$height = 600;

$image_p = imagecreatetruecolor($width, $height); 
$baseR = 255 - rand(0, 100);
$baseG = 255 - rand(0, 100);
$baseB = 255 - rand(0, 100);

for ($i = 0; $i <= floor($width / 40); $i++){
    for ($j = 0; $j <= floor($height / 40); $j++){
        $val = floor(100 * (rand(0, 100) / 100)); //value will always be within the range of 1-100
        $r = $baseR - $val;
        $g = $baseG - $val;
        $b = $baseB - $val;
        $color = imagecolorallocate($image_p, $r, $g, $b); 
        imagefilledellipse($image_p, $i * 40, $j * 40, ($i * 40), ($j * 40), $color);
    }
}

imagejpeg($image_p, uniqid() .'.jpg');

结果很糟糕。虽然我理解其余代码,但这一行 imagefilledellipse($image_p, $i * 40, $j * 40, ($i * 40), ($j * 40), $color); 超出了我的理解范围。请帮忙。

只是改变

imagefilledellipse($image_p, $i * 40, $j * 40, ($i * 40), ($j * 40), $color);

来自

 imagefilledellipse($image_p, $i * 40, $j * 40, 40, 40, $color);