Tuesday, February 3, 2026
HomeLanguagesPHP | ImagickKernel separate() Function

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.




<?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);
?>


Output:

Total number of attached kernels are: 4

Program 2 (Getting all ImagickKernel in a object):




<?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>");
?>


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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
124 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11979 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12066 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6935 POSTS0 COMMENTS
Umr Jansen
6919 POSTS0 COMMENTS