PHP | ImagickDraw setFillAlpha() Function
Last Updated :
30 Dec, 2019
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
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setFillColor( 'green' );
$draw ->setFillAlpha(0.3);
$draw ->setFontSize(80);
$draw ->annotation(100, 150, 'GeeksforGeeks' );
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setFillColor( 'green' );
$draw ->setFillAlpha(0.3);
$draw ->circle(300, 200, 230, 20);
$draw ->setFillColor( 'red' );
$draw ->setFillAlpha(0.5);
$draw ->rectangle(200, 300, 20, 100);
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickdraw.setfillalpha.php
Share your thoughts in the comments
Please Login to comment...