PHP | ImagickKernel fromBuiltIn() Function

The ImagickKernel::fromBuiltIn() function is an inbuilt function in PHP which is used to create a kernel from a builtin kernel.
Syntax:
ImagickKernel ImagickKernel::fromBuiltIn( int $kernelType, string $kernelString )
Parameters: This function accept two parameters as mentioned above and described below:
- $kernelType: It specifies the type of kernel.
- $kernelString: It specifies the string that describe the parameters.
Return Value: This function returns a new ImagickKernel object on success.
Exceptions: This function throws ImagickException on error.
Below programs illustrate the ImagickKernel::fromBuiltIn() function in PHP:
Program 1:
<?php   // Create a kernel from matrix $kernel = ImagickKernel::fromBuiltIn(Imagick::KERNEL_DIAMOND, "2");   echo "The matrix of Builtin kernel - Diamond: <br/>";   // Get the matrix from kernel $matrix = $kernel->getMatrix();   foreach ($matrix as $row) {     foreach ($row as $cell) {         if ($cell === false) {             $output .= "0";         } else {             $output .= $cell;         }     }     $output .= "<br>"; }   echo $output; ?> |
Output:
The matrix of Builtin kernel - Diamond: 00100 01110 11111 01110 00100
Program 2:
<?php   // Create a new imagick object $imagick = new Imagick(   // Create a kernel from built In types $kernel = ImagickKernel::fromBuiltIn(Imagick::KERNEL_SQUARE, "2");   // Scale the kernel $kernel->scale(2, Imagick::NORMALIZE_KERNEL_VALUE);   // Add the filter $imagick->filter($kernel);   // Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> |
Output:
Reference: https://www.php.net/manual/en/imagickkernel.frombuiltin.php
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek 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!




