Specifications
TABLE 19.1 Contents of the Bounding Box Array
Array Index Contents
0 X coordinate, lower-left corner
1 Y coordinate, lower-left corner
2 X coordinate, lower-right corner
3 Y coordinate, lower-right corner
4 X coordinate, upper-right corner
5 Y coordinate, upper-right corner
6 X coordinate, upper-left corner
7 Y coordinate, upper-left corner
To remember what the contents of the array are, just remember that the numbering starts at the
bottom-left corner of the bounding box and works its way around counterclockwise.
There is one tricky thing about the values returned from the ImageTTFBBox() function. They
are coordinate values, specified from an origin. However, unlike coordinates for images, which
are specified relative to the top-left corner, they are specified relative to a baseline.
Look at Figure 19.6 again. You will see that we have drawn a line along the bottom of most of
the text. This is known as the baseline. Some letters hang below the baseline, such as y in this
example. These are called descenders.
The left side of the baseline is specified as the origin of measurements—that is, X coordinate 0
and Y coordinate 0. Coordinates above the baseline have a positive X coordinate and coordi-
nates below the baseline have a negative X coordinate.
In addition to this, text might actually have coordinate values that sit outside the bounding box.
For example, the text might actually start at an X coordinate of –1.
What this all adds up to is the fact that care is required when performing calculations with
these numbers.
We work out the width and height of the text as follows:
$right_text = $bbox[2]; // right co-ordinate
$left_text = $bbox[0]; // left co-ordinate
$width_text = $right_text - $left_text; // how wide is it?
$height_text = abs($bbox[7] - $bbox[1]); // how tall is it?
Generating Images
C
HAPTER 19
19
G
ENERATING
IMAGES
417
24 7842 CH19 3/6/01 3:42 PM Page 417










