PHP | Imagick opaquePaintImage() Function
Last Updated :
27 Aug, 2019
The Imagick::opaquePaintImage() function is an inbuilt function in PHP which is used to replace the target color with the specified fill color value of any pixel that matches the target color.
Syntax:
bool Imagick::opaquePaintImage(Â $target, $fill, $fuzz,
$invert, $channel = Imagick::CHANNEL_DEFAULT ] )
Parameters: This function accepts five parameters as mentioned above and described below:
- $target: This parameter holds the ImagickPixel object or target color which need to be changed.
- $fill: This parameter holds the color for replacement.
- $fuzz: This parameter holds the amount of fuzz that will be in float type.
- $invert: Switch between 0 and 1 where 0 is normal and 1 is inverse.
- $channel: This parameter holds the Imagick channel constants that provide any channel constant which is valid for channel mode. More than one channel can be combined using bitwise operators.
Return Value: This function returns TRUE on success or FALSE on failure.
Below programs illustrate the Imagick::opaquePaintImage() function in PHP:
Program 1:
<?php
$imagePath =
$target = 'rgb(255, 255, 255)' ;
$fill = 'rgb(255, 234, 128)' ;
$fuzz = '0.1' ;
$invert = '0' ;
$imagick = new \Imagick( $imagePath );
$imagick ->setimageformat( 'png' );
$imagick ->opaquePaintImage(
$target , $fill , $fuzz * \Imagick::getQuantum(), $invert
);
$imagick ->despeckleimage();
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagePath =
$target = 'rgb(255, 255, 255)' ;
$fill = 'rgb(21, 200, 236)' ;
$fuzz = '0.1' ;
$invert = '0' ;
$imagick = new \Imagick( $imagePath );
$imagick ->setimageformat( 'png' );
$imagick ->opaquePaintImage(
$target , $fill , $fuzz * \Imagick::getQuantum(), $invert
);
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagick.opaquepaintimage.php
Share your thoughts in the comments
Please Login to comment...