Open In App

PHP | imagefilter() Function

The imagefilter() function is an inbuilt function in PHP which is used to apply an given filter on the image.

Syntax:



bool imagefilter( resource $image, int $filtertype,
       int $arg1, int $arg2, int $arg3, int $arg4 )

Parameters: This function accept six parameters as mentioned above and described below:

Return Value: This function returns TRUE on success or FALSE on failure.

Below given programs illustrate the imagefilter() function in PHP:

Program 1:




<?php
  
// Load the png image
$im = imagecreatefrompng(
  
// Negative the image
imagefilter($im, IMG_FILTER_NEGATE);
  
// Show the output
header('Content-type: image/png');
imagepng($im);
?>

Output:

Program 2:




<?php
  
// Load the png image
$im = imagecreatefrompng(
  
// Grayscale the image
imagefilter($im, IMG_FILTER_GRAYSCALE);
  
// Show the output
header('Content-type: image/png');
imagepng($im);
?>

Output:

Program 3:




<?php
  
// Load the png image
$im = imagecreatefrompng(
  
// Colorize the image
imagefilter($im, IMG_FILTER_COLORIZE, 140, 0, 140, 20);
  
// Show the output
header('Content-type: image/png');
imagepng($im);
?>

Output:

Reference: https://www.php.net/manual/en/function.imagefilter.php


Article Tags :