用PHP在图像的每个角落画正方形

用PHP在图像的每个角落画正方形,php,Php,我想在图像的每个角落画正方形,目前我已经在图像的左上角画了一个正方形 $canvas = imagecreatetruecolor(200, 200); //rectangle coordinates $array_rectangles = array(array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x

我想在图像的每个角落画正方形,目前我已经在图像的左上角画了一个正方形

$canvas = imagecreatetruecolor(200, 200);
//rectangle coordinates
$array_rectangles = array(array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)),array('x1' => mt_rand(0, 200),'y1' => mt_rand(0, 200),'x2' => mt_rand(0, 200),'y2' => mt_rand(0, 200)));
$white = imagecolorallocate($canvas, 255, 255, 255);
$background_color = imagecolorallocate($canvas, 25, 153, 206);
//creating ten rectangles.
foreach ($array_rectangles as $key => $point) {
imagefilledrectangle($canvas, $point['x1'], $point['y1'], $point['x2'], $point['y2'], $white);
} 
//creating square
imagefilledrectangle($canvas, 0, 0, 20, 20, $green);
imagepng($canvas,'img.png'); //saving image

我试过
imagefilledrectangle($canvas,200,0,20,20,$green)我得到以下结果


我认为您必须尝试:

imagefilledrectangle($canvas, 180, 0, 200, 20, $green);
imagefilledrectangle($canvas, 0, 180, 20, 200, $green);
imagefilledrectangle($canvas, 180, 180, 200, 200, $green);

x1必须小于x2,否则将向后打印。y1和y2也一样,我认为您必须尝试:

imagefilledrectangle($canvas, 180, 0, 200, 20, $green);
imagefilledrectangle($canvas, 0, 180, 20, 200, $green);
imagefilledrectangle($canvas, 180, 180, 200, 200, $green);
x1必须小于x2,否则将向后打印。y1和y2相同