HomePHP Filtering Image Streams with the GD Library in PHP
Filtering Image Streams with the GD Library in 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!
Welcome to the final installment of the series that began with "A Close Look at the GD Library in PHP." Comprised of five articles, this series introduces the most common operations that you can perform with this graphic-processing package. These range from creating basic image streams from scratch to performing more complex operations such as drawing shapes and filtering graphics.
As usual with many of my articles on web development, before I move on and continue exploring some additional functions integrated with the GD extension, I'd like to refresh the topics treated in the previous article of the series. This will give you a better idea of how the respective functions discussed in that tutorial can be linked with the ones that I plan to cover in the next few sentences.
Having said that, you'll surely recall that in the preceding article of the series I showed you how to display on the browser some basic filled shapes, including simple rectangles, ellipses and more complex polygons. In addition, I explained how to utilize the handy "imagex()", "imagey()" and "getimagesize()" functions to retrieve the width and height values for a given image stream, as well as determining its MIME type. As you can see, the GD extension has plenty of power when it comes to fetching useful data about a particular graphic, whether that graphic was created dynamically or generated from an existing picture.
All right, having summarized the concepts that I covered so far, in this article I'm going to demonstrate how the GD library can be used to apply some basic graphic filters (yes, like Photoshop, but much simpler) by utilizing the versatility of a brand new function called "imagefilter()".
As you'll see shortly, with this function it is possible to reverse, blur and highlight the colors of a determined image, as well as convert it to its grayscale version, among other things. Sounds pretty interesting, right?
So, are you ready to find out how to apply some basic graphic filters to a given image stream using the GD extension? Okay, let's get started!