In consonance with the concepts that I discussed in the section you just read, this last section will be focused upon covering the functions integrated with the GD package that retrieve the physical dimensions of a given image stream. To perform these tasks, the library offers the handy "imagex()" and "imagey()" functions, which can be used to retrieve the width and height of a specified image respectively. A pair of simple implementations for these functions is shown below, so study the corresponding code samples: // example of 'imagesx()' function try{ // example of 'imagesy()' function try{ Admittedly, getting the width and height values of a given image stream is actually a straightforward procedure, considering the simplicity of the functions. As you saw, they only take a reference of the image stream used to calculate its respective dimensions. Quite easy, right? Finally, as I said earlier, the GD library also offers another powerful function that fetches relevant information on a concrete image stream. This function is called "getimagesize()." It not only retrieves the respective width and height of the stream, but returns its MIME type as well in an array notation. Below I coded a demonstrative example that shows how to use this function: // example of 'getimagesize()' function if(!$imageData=getimagesize('clouds.gif')){ } See how easy it is to retrieve relevant information about a given image stream using the previous "getimagesize()" function? I'm sure you do! Of course, it's worthwhile to mention here that all of the examples included in this tutorial are just that: a friendly introduction to using the most important functions bundled with the GD extension. For full information about this package, the best place to go is the PHP official site. Final thoughts In this fourth part of the series, I walked you through using the GD functions that draw basic filled shapes, ranging from simple rectangles to more complex polygons. I also showed you a few additional functions for retrieving the dimensions of a specified image stream. In the last part of the series, I'll teach you how to take advantage of the capacity offered by the GD package to apply different types of filters to an existing graphic. Now that you've been warned, I think you won't want to miss it!
blog comments powered by Disqus |