PHP | ImagickKernel addUnityKernel() Function
The ImagickKernel::addUnityKernel() function is an inbuilt function in PHP which is used to add a given amount of the ‘Unity’ Convolution Kernel to the given kernel. This function is used to convert the defined kernels into blended soft-blurs, unsharp kernels or into sharpening kernels.
Syntax:
bool ImagickKernel::addUnityKernel( float $scale )
Parameters: This function accepts a single parameter $scale which holds the scale of unity kernel.
Return Value: This function returns TRUE on success.
Below programs illustrate the ImagickKernel::addUnityKernel() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$kernel = ImagickKernel::fromMatrix(
[[-1, 0, -1], [0, 4, 0], [-1, 0, 0]]);
$kernel ->addUnityKernel(0.7);
$imagick ->filter( $kernel );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$kernel = ImagickKernel::fromMatrix(
[[-3, 0, -2], [ 3, 4, 2], [-1, 0, -1]]);
echo "Before adding unity kernel: <br/>" ;
print ( "<pre>" .print_r( $kernel ->getMatrix(), true). "</pre>" );
$kernel ->addUnityKernel(12);
echo "After adding unity kernel: <br/>" ;
print ( "<pre>" .print_r( $kernel ->getMatrix(), true). "</pre>" );
?>
|
Output:
Before adding unity kernel:
Array
(
[0] => Array
(
[0] => -3
[1] => 0
[2] => -2
)
[1] => Array
(
[0] => 3
[1] => 4
[2] => 2
)
[2] => Array
(
[0] => -1
[1] => 0
[2] => -1
)
)
After adding unity kernel:
Array
(
[0] => Array
(
[0] => -3
[1] => 0
[2] => -2
)
[1] => Array
(
[0] => 3
[1] => 16
[2] => 2
)
[2] => Array
(
[0] => -1
[1] => 0
[2] => -1
)
)
Reference: https://www.php.net/manual/en/imagickkernel.addunitykernel.php
Last Updated :
14 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...