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

(singke) #1

Stretching Single-Pixel Images


The following technique takes advantage of the behavior of most browsers with the width
and height properties of the image tag. It does not require the GD extension, because it
doesn't actually manipulate an image. It relies on the browser to stretch an image to
match the width and height specified in the IMG tag. This allows you to stretch a single-
pixel image into a large bar.


Refer to Listing 19.5. An HTML table is used to line up graph labels with bars. The
largest data element will fill 100 percent of the graph width, which is specified by the
graphWidthMax variable. Each element is pulled from the data array and used to scale
graphWidthMax. This produces a horizontally oriented bar graph, but the same
method can make a vertical graph, too.


Listing 19.5 Bar Graph Using Stretched Images

Free download pdf