PHP | ImagickKernel scale() Function
The ImagickKernel::scale() function is an inbuilt function in PHP which is used to scale the given kernel list by the given amount.
Syntax:
void ImagickKernel::scale( float $scale, int $normalizeFlag )
Parameters: This function accept two parameters as mentioned above and described below:
- $scale: It specifies the amount of scale.
- $normalizeFlag: It specifies the type of scale.
Return Value: This function does not return any value.
Below programs illustrate the ImagickKernel::scale() function in PHP:
Program 1:
<?php
$imagick = new Imagick(
$matrix = [
[0, 0, 1],
[0, 2, 1],
[1, 1, 1],
];
$kernel = ImagickKernel::fromMatrix( $matrix );
echo 'Before scaling:<br>' ;
print ( "<pre>" .print_r( $kernel ->getMatrix(), true). "</pre>" );
$kernel ->scale(5, Imagick::NORMALIZE_KERNEL_VALUE);
echo 'After scaling:<br>' ;
print ( "<pre>" .print_r( $kernel ->getMatrix(), true). "</pre>" );
?>
|
Output:
Before scaling:
Array
(
[0] => Array
(
[0] => 0
[1] => 0
[2] => 1
)
[1] => Array
(
[0] => 0
[1] => 2
[2] => 1
)
[2] => Array
(
[0] => 1
[1] => 1
[2] => 1
)
)
After scaling:
Array
(
[0] => Array
(
[0] => 0
[1] => 0
[2] => 0.71428571428571
)
[1] => Array
(
[0] => 0
[1] => 1.4285714285714
[2] => 0.71428571428571
)
[2] => Array
(
[0] => 0.71428571428571
[1] => 0.71428571428571
[2] => 0.71428571428571
)
)
Program 2:
<?php
$imagick = new Imagick(
$matrix = [
[1, 2, -3],
[4, 5, 6],
[7, 8, 9]
];
$kernel = ImagickKernel::fromMatrix( $matrix );
$kernel ->scale(4, 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.scale.php
Last Updated :
14 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...