Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

PHP | ImagickKernel scale() Function

  • Last Updated : 14 Jan, 2020

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :