search for in the  
<imagefilltoborderimagefontheight>
Last updated: Thu, 19 May 2005

imagefilter

(PHP 5)

imagefilter --  Applies a filter to an image

Description

bool imagefilter ( resource src_im, int filtertype [, int arg1 [, int arg2 [, int arg3]]] )

imagefilter() applies the filter filtertype to the image, using arg1, arg2 and arg3 where necessary.

filtertype can be one of the following:

  • IMG_FILTER_NEGATE: Reverses all colors of the image.

  • IMG_FILTER_GRAYSCALE: Converts the image into grayscale.

  • IMG_FILTER_BRIGHTNESS: Changes the brightness of the image. Use arg1 to set the level of brightness.

  • IMG_FILTER_CONTRAST: Changes the contrast of the image. Use arg1 to set the level of contrast.

  • IMG_FILTER_COLORIZE: Like IMG_FILTER_GRAYSCALE, except you can specify the color. Use arg1, arg2 and arg3 in the form of red, blue, green. The range for each color is 0 to 255.

  • IMG_FILTER_EDGEDETECT: Uses edge detection to highlight the edges in the image.

  • IMG_FILTER_EMBOSS: Embosses the image.

  • IMG_FILTER_GAUSSIAN_BLUR: Blurs the image using the Gaussian method.

  • IMG_FILTER_SELECTIVE_BLUR: Blurs the image.

  • IMG_FILTER_MEAN_REMOVAL: Uses mean removal to achieve a "sketchy" effect.

  • IMG_FILTER_SMOOTH: Makes the image smoother. Use arg1 to set the level of smoothness.

Note: This function is only available if PHP is compiled with the bundled version of the GD library.

Returns TRUE on success or FALSE on failure.

Example 1. imagefilter() grayscale example

<?php
$im
= imagecreatefrompng('dave.png');
if (
$im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
   echo
'Image converted to grayscale.';
  
imagepng($im, 'dave.png');
} else {
   echo
'Conversion to grayscale failed.';
}

imagedestroy($im);
?>

Example 2. imagefilter() brightness example

<?php
$im
= imagecreatefrompng('sean.png');
if (
$im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20)) {
   echo
'Image brightness changed.';
  
imagepng($im, 'sean.png');
} else {
   echo
'Image brightness change failed.';
}

imagedestroy($im);
?>

Example 3. imagefilter() colorize example

<?php
$im
= imagecreatefrompng('philip.png');

/* R, G, B, so 0, 255, 0 is green */
if ($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0)) {
   echo
'Image successfully shaded green.';
  
imagepng($im, 'philip.png');
} else {
   echo
'Green shading failed.';
}

imagedestroy($im);
?>



User Contributed Notes
imagefilter
vdepizzol at hotmail dot com
04-Sep-2004 03:36
Examples using imagefilter():

<?php
$im
= imagecreatefrompng('dave.png');
if (
$im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
   echo
'Image converted to grayscale.';
  
imagepng($im, 'dave.png');
} else {
   echo
'Conversion to grayscale failed.';
}

imagedestroy($im);
?>

/////////////////////////////

<?php
$im
= imagecreatefrompng('sean.png');
if (
$im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20)) {
   echo
'Image brightness changed.';
  
imagepng($im, 'sean.png');
} else {
   echo
'Image brightness change failed.';
}

imagedestroy($im);
?>

/////////////////////////////

<?php
$im
= imagecreatefrompng('philip.png');

/* R, G, B, so 0, 255, 0 is green */
if ($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0)) {
   echo
'Image successfully shaded green.';
  
imagepng($im, 'philip.png');
} else {
   echo
'Green shading failed.';
}

imagedestroy($im);
?>
kees at tweakers dot net
20-Jul-2004 08:26
From what i have been able to find from this function, it accepts the following arguments:
       IMG_FILTER_NEGATE
       IMG_FILTER_GRAYSCALE
       IMG_FILTER_EDGEDETECT
       IMG_FILTER_GAUSSIAN_BLUR
       IMG_FILTER_SELECTIVE_BLUR
       IMG_FILTER_EMBOSS
       IMG_FILTER_MEAN_REMOVAL

The following arguments need one or more arguments.
       IMG_FILTER_SMOOTH, -1924.124
       IMG_FILTER_COLORIZE, -127.12, -127.98, 127
       IMG_FILTER_CONTRAST, -90
       IMG_FILTER_BRIGHTNESS, 98
      
I haven't tested them all, the names speak for themselves.

<imagefilltoborderimagefontheight>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT