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 // Create a new imagick object $imagick = new Imagick( $matrix = [ [0, 0, 1], [0, 2, 1], [1, 1, 1], ]; // Create a kernel from built-in matrix $kernel = ImagickKernel::fromMatrix($matrix); echo 'Before scaling:<br>'; print("<pre>".print_r($kernel->getMatrix(), true)."</pre>"); // Scale the kernel $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 // Create a new imagick object $imagick = new Imagick( $matrix = [ [1, 2, -3], [4, 5, 6], [7, 8, 9] ]; // Create a kernel from matrix $kernel = ImagickKernel::fromMatrix($matrix); // Scale the kernel $kernel->scale(4, 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.scale.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!




