HomePHP Page 4 - Filtering Image Streams with the GD Library in PHP
More graphic filters with the imagefilter() function - PHP
Building and processing dynamic images with PHP is a procedure that can be easily tackled with the GD extension. If you want to learn how to put its main functions to work for you, then you should start reading this tutorial right now!
As I mentioned in the previous section, the "imagefilter()" function provides PHP developers with a number of other graphic filters for controlling certain characteristics of a selected image stream. Of course, as you might guess, the application of these additional graphic filters can be easily performed by specifying the type of effect that must be implemented when calling the function.
Below I coded some illustrative examples which demonstrate how to apply different graphic filters to the same sample image that you saw in the previous section. You should notice that each code sample is accompanied by the respective resulting image after applying the appropriate filter.
This being said, here are the aforementioned examples, so take some time and have a look at them, please:
// example of 'imagefilter()' function - Colorizes the image
try{ if(!$image=imagecreatefromgif('clouds.gif')){ throw new Exception('Error creating image'); } // apply filter to image if(!imagefilter($image,IMG_FILTER_COLORIZE,255,0,0)){ throw new Exception('Error applying filter to image'); } // display image to the browser header("Content-type: image/gif"); imagegif($image); // free memory imagedestroy($image);
All right, I believe that the hands-on examples coded above should be explanatory enough in themselves to demonstrate the capacity offered by the "imagefilter()" function for applying different graphic filters to a specified image stream.
As with the majority of my articles on PHP development, feel free to modify all the code samples included in this tutorial. This will help you to improve your existing background in using the GD extension within your own PHP applications.
Final thoughts
Finally, this educational journey has come to an end. Hopefully, this series of articles has served as an approachable introduction to using the main functions that come packaged with the GD library. However, if you're looking for a complete reference on this PHP extension, the best place to go is the official PHP site.