Chhorn Soro
Chhorn Soro

Reputation: 3151

How can I set a border thinkness and color on a polygon image in PHP?

Now I am using PHP function "imagefilledpolygon" to draw the polygon over other images, but now I can set its background color only and I don't know how to set the polygon border thickness and border color.

Here is my polygon-drawing function

public function draw(){

    $image_src = DIR_UPLOADS . 'face.png';

    list($width, $height) = getimagesize(DIR_UPLOADS . 'face.png');

    $image = imagecreatefrompng($image_src);
    //$image = imagecreatetruecolor(400, 300);

    // Transparent polygon color background
    $poly_bg_color = imagecolorallocatealpha($image, 207, 199, 186, 50);


    $values = array(
        0,   0,
        150, 250,
        350, 250
    );

    // Draw a polygon
    imagefilledpolygon($image, $values, ((count($values)) / 2 ), $poly_bg_color);

    // Make it a Transparency Background
    imagealphablending($image, false);
    imagesavealpha($image, true);
    $transparentindex = imagecolorallocatealpha($image, 255, 255, 255, 127);
    imagefill($image, 0, 0, $transparentindex);

    imagepng($image, DIR_UPLOADS . 'out.png', 9);

    echo "<img src='/uploads/out.png?v=" . time() . "' />";

    imagedestroy($image);
}

Here is the result image

enter image description here

How can I do it?

Upvotes: 0

Views: 201

Answers (1)

Amega
Amega

Reputation: 138

I believe you just need to additionally draw a polygon using imagepolygon with the same set of points. To set line thickness, you may want to also call imagesetthickness function before that.

Upvotes: 1

Related Questions