php8.5
Home/ Manual/ imagick / imagick/ Imagick::filter

Imagick::filter

PHP function Deprecated as of PECL imagick 3.4.4 Edit on GitHub ✎

(PECL imagick 3 >= 3.3.0)

Applies a custom convolution kernel to the image

Function-3-4-4

Description

Imagick::filter(ImagickKernel $ImagickKernel, int $channel = Imagick::CHANNEL_UNDEFINED): bool

Applies a custom convolution kernel to the image.

Parameters

ImagickKernel

An instance of ImagickKernel that represents either a single kernel or a linked series of kernels.

channel

Channel

Return Values

Success

Examples

Imagick::filter()

php
<?php
function filter($imagePath) {
    $imagick = new \Imagick(realpath($imagePath));
    $matrix = [
        [-1, 0, -1],
        [0,  5,  0],
        [-1, 0, -1],
    ];
    
    $kernel = \ImagickKernel::fromMatrix($matrix);
    $strength = 0.5;    
    $kernel->scale($strength, \Imagick::NORMALIZE_KERNEL_VALUE);    
    $kernel->addUnityKernel(1 - $strength);

    $imagick->filter($kernel);
    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}

?>

Source: reference/imagick/imagick/filter.xml · from the official PHP manual (php/doc-en)