PHP | Imagick evaluateImage() Function
Last Updated :
17 Jul, 2019
The Imagick::evaluateImage() function is an inbuilt function in PHP which is used to apply an expression to the image. It can apply any arithmetic, logical or relational expression to an image and evaluate its result. This operator has many uses ranging from changing the brightness of an image i.e. lighten or darken the image, or changing the contrast of the image or to produce the negation of the image.
Syntax:
bool Imagick::evaluateImage( $evaluation_op, $constant, $channel = Imagick::CHANNEL_DEFAULT )
Parameters: This function accepts three parameters as mentioned above and described below:
- $evaluation_op: It holds the evaluation operator like add, subtracts, divides, mod, etc.
- $constant: It holds the value of the operator with the evaluation will take place.
- $channel: It provides any channel constant that is appropriate for required channel mode.
Return Value: It returns Boolean value true if function is successfully executed otherwise returns false.
Below programs illustrate the Imagick::evaluateImage() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$evaluation_op = Imagick::EVALUATE_DIVIDE;
$constant = 3;
$channel = Imagick::CHANNEL_ALPHA;
$imagick ->evaluateImage( $evaluation_op , $constant , $channel );
header( "Content-Type: image/jpg" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$image = new Imagick(__DIR__ . '\sample.png' );
$image ->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);
$evaluation_op = Imagick::EVALUATE_DIVIDE;
$constant = 3;
$channel = Imagick::CHANNEL_ALPHA;
$image ->evaluateImage( $evaluation_op , $constant , $channel );
header( 'Content-type: image/jpeg' );
$image ->writeImage(__DIR__ . '\sample_with_33perc_opacity.png' );
?>
|
Output:
Program 3:
<?php
function Evaluate_Image( $image , $evaluation_op , $constant , $channel )
{
$image ->evaluateImage( $evaluation_op , $constant , $channel );
return $image ;
}
$final_image = Evaluate_Image( new Imagick(__DIR__ . '\sample.png' ),
Imagick::EVALUATE_MEAN, 3, Imagick::CHANNEL_BLUE);
header( 'Content-type: image/jpeg' );
echo $final_image ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagick.evaluateimage.php
Please comment if you find something wrong or want to add some more information. Happy coding!!
Share your thoughts in the comments
Please Login to comment...