The ImagickDraw::setFillAlpha() function is an inbuilt function in PHP which is used to set the opacity to use when drawing using the fill color or fill texture.
Syntax:
bool ImagickDraw::setFillAlpha( float $opacity )
Parameters: This function accepts a single parameter $opacity which holds the opacity of the color where 1 means opaque and 0 means transparent.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickDraw::setFillAlpha() function in PHP:
Program 1:
<?php   // Create a new imagick object $imagick = new Imagick();   // Create a image on imagick object $imagick->newImage(800, 250, 'white');   // Create a new imagickDraw object $draw = new ImagickDraw();   // Set the color to green $draw->setFillColor('green');   // Set the opacity $draw->setFillAlpha(0.3);   // Set the font size $draw->setFontSize(80);   // Annotate a text $draw->annotation(100, 150, 'neveropen');   // Render the draw commands $imagick->drawImage($draw);   // Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> |
Output:
Program 2:
<?php   // Create a new imagick object $imagick = new Imagick();   // Create a image on imagick object $imagick->newImage(800, 250, 'white');   // Create a new imagickDraw object $draw = new ImagickDraw();   // Set the color to green $draw->setFillColor('green');   // Set the opacity $draw->setFillAlpha(0.3);   // Draw a circle $draw->circle(300, 200, 230, 20);   // Set the color to red $draw->setFillColor('red');   // Set the opacity $draw->setFillAlpha(0.5);   // Draw a rectangle $draw->rectangle(200, 300, 20, 100);   // Render the draw commands $imagick->drawImage($draw);   // Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> |
Output:
Reference: https://www.php.net/manual/en/imagickdraw.setfillalpha.php

