Imagefilter

This tutorial covers PHP GD image filters. The top image is the original, followed by changes made by the different filters.

Original

IMG_FILTER_NEGATE: Reverses all colors of the image.

IMG_FILTER_GRAYSCALE: Converts the image into grayscale.

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 (applied 3 times).

IMG_FILTER_SELECTIVE_BLUR: Blurs the image.

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

IMG_FILTER_BRIGHTNESS,-255
Arg -255 = min brightness, 0 = no change, +255 = max brightness (anything above 100 begins to fade)

IMG_FILTER_BRIGHTNESS,100

IMG_FILTER_CONTRAST,-100
Arg -100 = max contrast, 0 = no change, +100 = min contrast (over 50 fades to solid gray)

IMG_FILTER_CONTRAST,50

IMG_FILTER_COLORIZE,0,-150,-150
IMG_FILTER_COLORIZE Adds (subtracts) specified RGB values to each pixel. The valid range for each color is -255 to +255, The correct order is red, green, blue. -255 = min, 0 = no change, +255 = max

IMG_FILTER_COLORIZE,0,150,150

IMG_FILTER_SMOOTH,-8
IMG_FILTER_SMOOTH Applies a 9-cell convolution matrix where center pixel has the weight arg1 and others weight of 1.0. The result is normalized by dividing the sum with arg1 + 8.0 (sum of the matrix), any float is accepted, large value (in practice: 2048 or more) = no change

IMG_FILTER_SMOOTH,8
PHP version 5.3.0 Pixelation support (IMG_FILTER_PIXELATE) was added.
PHP version 5.2.5 Alpha support for IMG_FILTER_COLORIZE was added.
I am on a server running PHP 5.1.0 and do not have access to these filters. You can check what version of php you are running by putting this code into a file.
<?php
phpinfo();
?>
There are other ways to get image effects with PHP. I will cover some of those in the next lesson. The basic code for these filters are on the right. Right click, select all, ctrl+c to copy.