how to draw semi-transparent rectangle in php?

…衆ロ難τιáo~ 提交于 2019-11-29 02:21:11

You need to use http://php.net/manual/en/function.imagefilledrectangle.php, passing a color created with http://www.php.net/manual/en/function.imagecolorallocatealpha.php.

As you can see, the example for http://php.net/manual/en/function.imagefilledrectangle.php is pratically what to you want to do.

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!