PHP | ImagickKernel separate() Function

The ImagickKernel::separate() function is an inbuilt function in PHP which is used to separate a linked set of kernels and returns an array of ImagickKernels. This function is used to count the kernels in an object or see the kernels of an object.

Syntax:

array ImagickKernel::separate( void )

Parameters: This function doesn’t accepts any parameter.



Return Value: This function returns an array value containing the ImagickKernels.

Below programs illustrate the ImagickKernel::separate() function in PHP:

Program 1: This program counting all the kernels in an ImagickKernel.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
$matrix1 = [
    [-1, -1, -1],
    [4, 4, 4],
    [1, 1, 1],
];
  
$matrix2 = [
    [-1, 0, 0],
    [0, 0, 1],
    [-1, 0, 1],
];
  
$matrix3 = [
    [-1, 1, 0],
    [0, 0, 1],
    [-1, 0, 1],
];
  
$matrix4 = [
    [0, 1, 0],
    [0, 0, 1],
    [-1, 0, 1],
];
  
// Create ImagickKernel objects from matrices
$kernel1 = ImagickKernel::fromMatrix($matrix1);
$kernel2 = ImagickKernel::fromMatrix($matrix2);
$kernel3 = ImagickKernel::fromMatrix($matrix3);
$kernel4 = ImagickKernel::fromMatrix($matrix4);
  
// Add the kernels
$kernel1->addKernel($kernel2);
$kernel1->addKernel($kernel3);
$kernel1->addKernel($kernel4);
  
$kernelList = $kernel1->separate();
  
echo 'Total number of attached kernels are: ';
echo count($kernelList);
?>

chevron_right


Output:

Total number of attached kernels are: 4

Program 2 (Getting all ImagickKernel in a object):

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
$matrix1 = [
    [-1, -1, -1],
    [4, 4, 4],
    [1, 1, 1],
];
  
$matrix2 = [
    [-1, 0, 0],
    [0, 0, 1],
    [-1, 0, 1],
];
  
// Create ImagickKernel objects from matrices
$kernel1 = ImagickKernel::fromMatrix($matrix1);
$kernel2 = ImagickKernel::fromMatrix($matrix2);
  
// Add the kernel
$kernel1->addKernel($kernel2);
  
$kernelList = $kernel1->separate();
  
echo 'All the kernels are: ';
print("<pre>".print_r($kernelList, true)."</pre>");
?>

chevron_right


Output:

All the kernels are:
Array
(
    [0] => ImagickKernel Object
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [0] => -1
                            [1] => -1
                            [2] => -1
                        )

                    [1] => Array
                        (
                            [0] => 4
                            [1] => 4
                            [2] => 4
                        )

                    [2] => Array
                        (
                            [0] => 1
                            [1] => 1
                            [2] => 1
                        )

                )

        )

    [1] => ImagickKernel Object
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [0] => -1
                            [1] => 0
                            [2] => 0
                        )

                    [1] => Array
                        (
                            [0] => 0
                            [1] => 0
                            [2] => 1
                        )

                    [2] => Array
                        (
                            [0] => -1
                            [1] => 0
                            [2] => 1
                        )

                )

        )

)

Reference: https://www.php.net/manual/en/imagickkernel.separate.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.