Syntax:bool Imagick::transparentPaintImage (mixed $target, float $alpha, float $fuzz, bool $invert)
Parameters:This function takes four parameters as above and described below:
- $target:target color for drawing transparent.
- $alpha:transparency range: 1.0 is fully opaque and 0.0 is fully transparent.
- $fuzz:if TRUE paints any pixel that does not match the target color.
- $invert:whitePoint image.
Return value: this function returns Trueon success.
The following program illustrates the Imagick::transparentPaintImage() function in PHP:
Example: // $source = & quot; gfg_350X350.png & quot ;;
$source
=
" https://media.engineerforengineer.org/wp-content/uploads/20190809013546/gfg_350X350.png "
;
$target
=
"transpaintimg.png "
;
$color
=
"rgb (39 , 194, 255) "
;
$alpha
=
"0.5"
;
$fuzz
=
"0.1"
;
$inverse
=
"normal"
;
$imagick
=
new
Imagick (
realpath
(
$source
));
// Must be in a format that supports transparency
$imagick
-> setimageformat (
’png’
);
$imagick
-> transparentPaintImage (
$color
,
$alpha
,
$fuzz
* Imagick::getQuantum(),
$inverse
);
// Not required, but helps to remove the remaining pixels
$imagick
-> despeckleimage();
$canvas
=
new
Imagick();
$canvas
-> newPseudoImage (
$imagick
-> getImageWidth(),
$imagick
-> getImageHeight(),
"pattern: checkerboard"
);
$canvas
-> compositeimage (
$imagick
, Imagick: : COMPOSITE_ATOP, 0, 0);
$canvas
-> setImageFormat (
’png’
);
header (
" Content-Type: image / png "
);
echo
$canvas
-> getImageBlob();
$canvas
-> WriteImage (
$target
);
?>
Output: Link: https://www.php.net/manual/en/imagick.transparentpaintimage.php