Computer >> Computer tutorials >  >> Programming >> PHP

imageconvolution() function in PHP


The imageconvolution() function

Syntax

bool imageconvolution (img, matrix, div, offset )

Parameters

  • img: Create image with imagecreatetruecolor() function.

  • matrix: A 3x3 matrix is an array of three arrays of three floats.

  • div: Divisor of the result of the convolution, used for normalization.

  • offset: The color offset.

Return

The imageconvolution() function returns True on success or False on failure.

Example

The following is an example

<?php
   $img = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   $arr = array(array(2, 0, 1), array(-1, -1, 0), array(0, 0, -1));
   imageconvolution($img, $arr, 1, 127);
   header('Content-Type: image/png');
   imagepng($img, null, 9);
?>

Output

The following is the output

imageconvolution() function in PHP

Example

Let us see another example with different parameter values for the same image. You can easily spot the difference now:

<?php
   $img = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   $arr = array(array(3, 2, 1), array(0, 1, 0), array(1, -1, -1));
   imageconvolution($img, $arr, 3, 110);
   header('Content-Type: image/png');
   imagepng($img, null, 9);
?>

Output

The following is the output

imageconvolution() function in PHP