PHP 8.3.4 Released!

Imagick::convolveImage

(PECL imagick 2, PECL imagick 3)

Imagick::convolveImageApplique un noyau de convolution à une image

Description

public Imagick::convolveImage(array $kernel, int $channel = Imagick::CHANNEL_DEFAULT): bool

Applique un noyau de convolution à une image.

Liste de paramètres

kernel

Le noyau de convolution

channel

Fournit une constante de canal valide pour votre mode de canal. Pour utiliser plus d'un canal, combinez les constantes de type de canal en utilisant les opérateurs de bits. Reportez-vous à la liste des constantes de canal.

Valeurs de retour

Retourne true en cas de succès.

Erreurs / Exceptions

Lance une exception ImagickException si une erreur survient.

Exemples

Exemple #1 Exemple avec Imagick::convolveImage()

<?php
function convolveImage($imagePath, $bias, $kernelMatrix) {
$imagick = new \Imagick(realpath($imagePath));
//$edgeFindingKernel = [-1, -1, -1, -1, 8, -1, -1, -1, -1,];
$imagick->setImageBias($bias * \Imagick::getQuantum());
$imagick->convolveImage($kernelMatrix);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

add a note

User Contributed Notes 2 notes

up
0
ahmed at zigzapps dot com
4 years ago
The provided example is wrong. Here's a correct sample:

$matrix = [[1,-1,1],[-1,1,-1],[1,-1,1]];
$kernel = \ImagickKernel::fromMatrix($matrix);

$imagick = new Imagick();
$imagick->readimage($file.'/z.png');
$imagick->convolveImage ($kernel);
$imagick->writeimage('convolve.png');
$imagick->clear();
$imagick->destroy();
up
-1
peter at musicalsaw dot com
10 years ago
Example of convolveImage:

<?php
// run an edge detection filter on an image
$image = new imagick( "diana.png" );
$edgeArray = array(-1,-1,-1,-1,8,-1,-1,-1,-1);
$image->convolveImage ($edgeArray);
$image->thresholdImage(1);
header('Content-type: image/png');
echo
$image;
?>
To Top