PHP | Imagick setImageOpacity() Function
The Imagick::setImageOpacity() function is an inbuilt function in PHP which is used to set the opacity level of an Imagick object. This method is available in ImageMagick 6.3.1 or newer versions.
Syntax:
bool Imagick::setImageOpacity( $opct )
Parameters: This function accepts single parameter $opct which specifies the opacity of Imagick object to be set.
Return Value: This function returns True on success.
Below programs illustrate the Imagick::setImageOpacity() function in PHP:
Original Image:
Program 1:
<?php
$im = new Imagick(
$im ->setImageOpacity(0.3);
header( "Content-Type: image/jpg" );
echo $im ->getImageBlob();
?>
|
Output:
Original Image:
Program 2:
<?php
$string = "Computer Science portal for Geeks!" ;
$im = new Imagick();
$draw = new ImagickDraw();
$draw ->setFillColor( new ImagickPixel( 'green' ));
$draw ->setFontSize(50);
$matrix = $im ->queryFontMetrics( $draw , $string );
$draw ->annotation(0, 40, $string );
$im ->newImage( $matrix [ 'textWidth' ], $matrix [ 'textHeight' ],
new ImagickPixel( 'white' ));
$im ->drawImage( $draw );
$im ->setImageFormat( 'jpeg' );
$im ->setImageOpacity(0.9);
header( "Content-Type: image/jpg" );
echo $im ->getImageBlob();
?>
|
Output:
Reference: http://php.net/manual/en/imagick.setimageopacity.php
Last Updated :
10 Jan, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...