使用PHP中的GD库创建带圆圈图案的图像

时间:2015-10-04 19:45:00

标签: php gd

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

enter image description here

我需要用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);超出了我的范围。请帮忙。

enter image description here

1 个答案:

答案 0 :(得分:1)

只需更改

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

通过

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

enter image description here

相关问题