PHP | ImagickDraw setFillAlpha() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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, 'GeeksforGeeks');
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagickdraw.setfillalpha.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.