As I stated previously, the GD library doesn't run short when it comes to generating brand new image streams from existing graphics. As you saw in the prior section, it's easy to create dynamic images by utilizing an initial GIF picture. This capacity can be extended to build images of different formats. That's precisely the case with the "imagecreatefromjpeg()" function. As you can probably guess from the name, it allows you to build a new image stream from an existing JPEG graphic. Its use is very intuitive, as is adequately shown by the following code sample: // example of 'imagecreatefromjpeg()' function try{ As shown above, the brand new "imagecreatefromjpeg()" function behaves in a fashion that is nearly identical to the "imagecreatefromgif()" function that you learned in the previous section. Of course, the only difference to spot here is that in this case, the function in question takes a JPEG image as its input argument. Quite simple, right? To complement the correct implementation of the previous example, suppose that the JPEG image inputted into the function is the following:
Then, based upon this input parameter, the prior example would output to the browser the below image stream:
Also, as you might guess, it's extremely easy to define a simple wrapper for the "imagecreatefromjpeg()" function, to facilitate it within a determined PHP application. Having said that, this condition is clearly reflected by the following code sample: // example of 'imagecreatefromjpeg()' function try{ So far, so good. At this time, I'm pretty certain that you understand how the previous "imagecreatefromjpeg()" function works. And since it's very simple to follow, I won't spend more time discussing how it functions. So what's the next step? Well, as I said earlier, the GD library comes equipped with yet another image preprocessing function, which is quite handy for creating new image streams from an existing PNG image. In other words, it behaves very similarly to the "imagecreatefromgif()" and "imagecreatefromjpeg()" functions that you have already learned. Therefore, in the next section I'll show you how to perform this task via the brand new "imagecreatefrompng()" function included in the GD extension. Click on the link below and keep reading.
blog comments powered by Disqus |