PHP | ImagickKernel fromMatrix() Function
Last Updated :
14 Jan, 2020
The ImagickKernel::fromMatrix() function is an inbuilt function in PHP which is used to create a kernel from an 2d matrix of values. The value of 2d matrix is either float if element is used otherwise false if element is skipped.
Syntax:
ImagickKernel ImagickKernel::fromMatrix( array $matrix, array $origin )
Parameters: This function accepts two parameters as mentioned above and described below:
- $matrix: It specifies the matrix of values that define the kernel. Values can be float or false.
- $origin (optional): It specifies the element of kernel that should be used as the origin pixel. This is only required in case of non-square matrix.
Return Value: This function returns a new ImagickKernel object on success.
Below programs illustrate the ImagickKernel::fromMatrix() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$matrix = [
[-1.5, -1, -0.2],
[0, 1, 1],
[0, 0.5, 1],
];
$kernel = ImagickKernel::fromMatrix( $matrix );
$imagick ->filter( $kernel );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick(
$matrix = [
[1, 2, -3],
[4, 5, 6],
[7, 8, 9]
];
$kernel = ImagickKernel::fromMatrix( $matrix );
$matrix = $kernel ->getMatrix();
print ( "<pre>" .print_r( $matrix , true). "</pre>" );
?>
|
Output:
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => -3
)
[1] => Array
(
[0] => 4
[1] => 5
[2] => 6
)
[2] => Array
(
[0] => 7
[1] => 8
[2] => 9
)
)
Reference: https://www.php.net/manual/en/imagickkernel.frommatrix.php
Share your thoughts in the comments
Please Login to comment...