Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

and the top and left sides are drawn with the highlight color. This creates an illusion of
the button being three-dimensional.


To finish the button, the script draws the label. First the text is drawn slightly off center
in the shadow color. Then the text is drawn in the highlight color over it and exactly
centered, making the text look as though it is floating over the button.


At this point the script has created the image and needs to send it to the browser. It is very
important that the header be sent to let the browser know that this file is a JPEG. Without
it, you get a garbled bunch of strange characters.


This wraps up the script that creates a button, but to really make use of it, we have to use
it in the context of a Web page. Listing 19.2 demonstrates the minimal steps. I've
created an array of four button labels I want to create. I then loop through the array, each
time creating an image tag. The source of the image is the previous script. I pass the
script some parameters to set the size of the button and the label. I leave the font as the
default, but I could have set that as well.


Listing 19.2 Creating Button Dynamically

Free download pdf