Specifications

After we have this, we test the loop condition:
} while ( $font_size>8 &&
( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
);
We are testing two sets of conditions here. The first is that the font is still readabletheres no
point in making it much smaller than 8 point because the button becomes too difficult to read.
The second set of conditions tests whether the text will fit inside the drawing space we have
for it.
Next, we check to see whether our iterative calculations found an acceptable font size or not,
and report an error if not:
if ( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
{
// no readable font size will fit on button
echo “Text given will not fit on button.<BR>”;
}
Positioning the Text
If all was okay, we next work out a base position for the start of the text. This is the midpoint
of the available space.
$text_x = $width_image/2.0 - $width_text/2.0;
$text_y = $height_image/2.0 - $height_text/2.0 ;
Because of the complications with the baseline relative co-ordinate system, we need to add
some correction factors:
if ($left_text < 0)
$text_x += abs($left_text); // add factor for left overhang
$above_line_text = abs($bbox[7]); // how far above the baseline?
$text_y += $above_line_text; // add baseline factor
$text_y -= 2; // adjustment factor for shape of our template
These correction factors allow for the baseline and a little adjustment because our image is a
bit top heavy.
Advanced PHP Techniques
P
ART IV
418
24 7842 CH19 3/6/01 3:42 PM Page 418