我正在尝试在 php 中创建一个简单的函数,它将接受一些 int 输入并使用它们来绘制一个矩形,但下面的函数不起作用......
<?php
$img = imagecreatetruecolor(500, 500);
$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0);
//set canvas background to white
imagefill($img, 0, 0, $white);
//THIS FUNCTION IS NOT WORKING
function draw($x1Pos, $y1Pos, $x2Pos, $y2Pos, $colour) {
imagerectangle($img, $x1Pos, $y1Pos, $x2Pos, $y2Pos, $colour);
}
draw(20, 40, 60, 80, $red);
draw(30, 40, 80, 100, $green);
imagerectangle($img, 150, 100, 300, 250, $green);
imagerectangle($img, 100, 100, 200, 200, $blue);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>