Syntax:bool Imagick::colorMatrixImage (array $color_matrix = Imagick::CHANNEL_DEFAULT)
Parameters:This function takes one parameter,
$color_matrix,which is used to store a 5x5 matrix for RGBA with rows denoting red, green, blue, alpha output, and columns - red, green, blue, alpha input, while the last row and columns to adjust brightness. In a 6x6 matrix for CMYKA, where rows represent cyan, magenta, yellow, tonal or black, alpha output, and columns - cyan, magenta, yellow, tonal or black, alpha input and alpha to adjust brightness similarly in RGBA, CMYKA also has last row and columns to adjust brightness.
Return value: this function returns True on success and returns False on error.The following program illustrates the Imagick::colorMatrixImage() function in PHP:Program:
// 6x6 color matrix for CMYKA
$colorMatrix
= [
1.5 , 0.0, 0.0, 0.0, 0.0, -0.157,
0.0, 0.0, 0.5, 0.0, 0 .0, -0.157,
0.0, 0.0, 0.0, 0.0, 0.5, -0.157 ,
0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 0.5, 0.0, 1.0
];
// Create Imagick object
$imagick
=
new
Imagick (
’ https://cdncontribute.engineerforengineer.org/wp-content/uploads/engineerforengineer-13.png ’
) ;
// Set the opacity of the image
$imagick
-> evaluateImage (
Imagick::EVALUATE_MULTIPLY,
0.6,
Imagick::CHANNEL_ALPHA
);
// Create a new Imagick object
$background
=
new
Imagick();
// Create a new pseudo image with a hexagon pattern
$background
-> newPseudoImage (
$imagick
-> getImageWidth(),
$imagick
-> getImageHeight(),
"pattern: hexagons"
);
// Set image format
$background
-> setImageFormat (
’png’
);
$imagick
-> setImageFormat (
’png’
);
// Use the Imagick function::colorMatrixImage()
$imagick
-> colorMatrixImage (
$colorMatrix
);
// Use the Imagick function::composite image()
$background
-> compositeImage (
$imagick
,
Imagick::COMPOSITE_SRCATOP,
0,
0
);
header (
" Content-Type: image / png "
);
// Display the output image
echo
$background
-> getImageBlob();
?>
Output: Link: https://www.php.net/manual/en/imagick.colormatriximage.php