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 // Create a new imagick object $imagick = new Imagick( // Create a kernel from matrix $kernel = ImagickKernel::fromMatrix( [[-1, 0, -1], [0, 4, 0], [-1, 0, 0]]); // Add the Unity Kernel $kernel ->addUnityKernel(0.7); // Add the filter $imagick ->filter( $kernel ); // Show the output $imagick ->setImageFormat( 'png' ); header( "Content-Type: image/png" ); echo $imagick ->getImageBlob(); ?> |
Output:
Program 2:
<?php // Create a kernel from matrix $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>" ); // Add the Unity Kernel $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
Please Login to comment...