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

(singke) #1

company that issues only one press release a month, you are better off creating these
graphics by hand. With a company that issues a press release each week, it starts to make
sense to automate the process. You can put the press releases into a database and generate
a graphic on the fly as surfers view the list of press releases. One advantage of this
approach is that if the CEO finds out you're putting flaming newspapers on the site, you
can make a minor modification and the graphics become the company logo with the
press-release title over it.


Seriously, you must consider the tradeoffs associated with dynamically created graphics.
You don't want to save yourself 15 minutes a month if it makes every page download 30
seconds longer. If you've been working with the Web for any time at all, you know to
reuse graphics throughout the site because the browser caches them. The first page may
take longer to load, but each successive page is faster because the graphics are already
loaded in the browser. Dynamic graphics can be cached, of course, but the browser uses
the URL to cache files. The GET-method form variables are part of the URL, so
http://www.site.com/button.php3?label=home&from=1 and
http://www.site.com/button.php3?label=home&from=2 may create two identical
graphics but are different as far as the browser cache is concerned.


These are only some of the issues involved with dynamic buttons. To demonstrate the
process, I'll provide an example and describe the steps. Listing 19.1 is a script that
creates a JPEG of a button with a text label. The button is rectangular and has some
highlighting and shadowing. The label has a drop-shadow effect applied to it and is
centered both vertically and horizontally.


Listing 19.1 JPEG Button


<?
/*
JPEG button
Creates a graphical button based
* on form variables.
/


//set parameters if not given
if(!isset($ButtonWidth))
{
$ButtonWidth = 100;
}


if(!isset($ButtonHeight))
{
$ButtonHeight = 30;
}


if(!isset($ButtonLabel))
{

Free download pdf