how to draw semi-transparent rectangle in php?

前端 未结 2 962
失恋的感觉
失恋的感觉 2020-12-16 04:23

Here is an example what I would like to do:

\"enter

Here is the result:

<
相关标签:
2条回答
  • 2020-12-16 04:46
    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);
    
    0 讨论(0)
  • 2020-12-16 04:49

    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.

    0 讨论(0)
提交回复
热议问题