как рисовать полупрозрачный прямоугольник в php?

Вот пример того, что я хотел бы сделать:

введите описание изображения здесь

Вот результат:

function red_rectangle($img_src,$x1,$y1,$x2,$y2,$tr = 50) { // Load image $img = imagecreatefromjpeg($img_src); // Transparent red $red = imagecolorallocatealpha($img, 255, 0, 0, $tr); // Draw a white rectangle imagefilledrectangle($img, $x1, $y1, $x2, $y2, $red); // Save the image (overwrite) imagejpeg($img, $img_src); imagedestroy($img); } 

Вам необходимо использовать http://php.net/manual/en/function.imagefilledrectangle.php , передавая цвет, созданный с помощью http://www.php.net/manual/en/function.imagecolorallocatealpha.php .

Как вы можете видеть, пример http://php.net/manual/en/function.imagefilledrectangle.php – это то, что вам нужно делать.

 function red_rectangle($img_src,$x1,$y1,$x2,$y2,$tr = 100) { // Load image $img = imagecreatefromjpeg($img_src); // Transparent red $red = imagecolorallocatealpha($img, 255, 0, 0, $tr); // Draw a white rectangle imagefilledrectangle($img, $x1, $y1, $x2, $y2, $red); // Don't forget to output a correct header header('Content-Type: image/jpg'); // Save the image (overwrite) imagejpeg($img); imagedestroy($img); } $img_src = 'test.jpg'; $x1= 500; $y1= 450; $x2 = 370; $y2=180; red_rectangle($img_src,$x1,$y1,$x2,$y2);