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
$kernel = ImagickKernel::fromBuiltIn(Imagick::KERNEL_DIAMOND, "2" );
echo "The matrix of Builtin kernel - Diamond: <br/>" ;
$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
$imagick = new Imagick(
$kernel = ImagickKernel::fromBuiltIn(Imagick::KERNEL_SQUARE, "2" );
$kernel ->scale(2, Imagick::NORMALIZE_KERNEL_VALUE);
$imagick ->filter( $kernel );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickkernel.frombuiltin.php
Last Updated :
14 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...