In according with the concepts that I deployed in the previous section, the GD library comes bundled with yet another powerful image preprocessing function. This function is helpful for creating a new stream from an existing PNG graphic. I'm talking about the "imagecreatefrompng()" function, which works in a way that is closely similar to all the other preprocessing functions that I showed you in the earlier sections of this tutorial. Now that I have explained how this brand new GD function works, please take a look at the following hands-on example, which precisely illustrates its functioning: // example of 'imagecreatefrompng()' function try{ As illustrated above, the "imagecreatefrompng()" function is nearly identical to the previous ones in the way it works. As you can see, the function takes a PNG image as its input argument, which is quite useful for building a new graphic using this popular image format. Also, provided that the existing PNG image inputted into the function is the following:
The image stream outputted to the browser after running the previous example would be similar to this:
And finally, by following the same approach that I utilized with all the prior GD functions discussed here, below I coded a basic wrapper for the already familiar "imagecreatefrompng()" function. It looks like this: // example of 'imagecreatefrompng()' function try{ Quite simple to grasp, right? After studying the signature of the above example, and naturally, of all the others developed previously, you'll certainly agree with me that the GD library makes creating different image streams from existing graphics a truly painless process. Besides, it's fair to mention that the GD extension also supports seamlessly the generation of dynamic image streams from other graphic formats, like WBMP, etc., but in this tutorial I only covered the most popular ones. Final thoughts In this second part of the series you learned how to use the capacity provided by some functions integrated with the GD extension to create dynamic image streams from existing graphics. As you saw here, this process was quite easy to follow, so I believe that you won't have any serious problems using these functions in your own PHP scripts. Now, focusing specifically on the topics that will be discussed in the next part of the series, you'll learn how to create new images from data strings. You'll also learn how to utilize the drawing functions that come with the GD library. I think that you won't want to miss it!
blog comments powered by Disqus |