Imagick::filter
(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
ImagickKernelAn instance of ImagickKernel that represents either a single kernel or a linked series of kernels.
channelChannel
Return Values
Success
Examples
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();
}
?>