Forum Moderators: coopster

Message Too Old, No Replies

PHP Script Error - Can't find/open font?

         

EJCrew

8:07 pm on Dec 3, 2005 (gmt 0)

10+ Year Member



I'm a neophyte with php/mysql and am trying to set up a poll on a webpage using an existing script. When I test the poll, I get these messages:

Warning: imagettfbbox(): Could not find/open font in /hsphere/local/home/#*$!/#*$!.com/show_poll.php on line 100

Warning: imagettftext(): Could not find/open font in /hsphere/local/home/xxx/xxx.com/show_poll.php on line 107

The script has this code to set the variable for the font:

// set up constants
putenv('GDFONTPATH=C:\WINDOWS\Fonts');
$width=120; // width of image in pixels - this will fit in 640x480
$left_margin = 10; // space to leave on left of graph
$right_margin= 10; // ditto right
$bar_height = 10;
$bar_spacing = $bar_height/2;
$fontname = 'verdana';
$title_size= 10; // point
$main_size= 10; // point
$small_size= 10; // point
$text_indent = 10; // position for text labels from edge of image

The code that won't execute:

// Add title
$title = 'Results';
$title_dimensions = ImageTTFBBox($title_size, 0, $fontname, $title);
$title_length = $title_dimensions[2] - $title_dimensions[0];
$title_height = abs($title_dimensions[7] - $title_dimensions[1]);
$title_above_line = abs($title_dimensions[7]);
$title_x = ($width-$title_length)/2; // center it in x
$title_y = ($y - $title_height)/2 + $title_above_line; // center in y gap
ImageTTFText($im, $title_size, 0, $title_x, $title_y,
$text_color, $fontname, $title);

// Draw a base line from a little above first bar location
// to a little below last
ImageLine($im, $x, $y-5, $x, $height-15, $line_color);

/*******************************************
Draw data into graph
*******************************************/
// Get each line of db data and draw corresponding bars
while ($row = mysql_fetch_object ($result))
{
if ($total_votes > 0)
$percent = intval(round(($row->num_votes/$total_votes)*100));
else
$percent = 0;

// display percent for this value
$percent_dimensions = ImageTTFBBox($main_size, 0, $fontname, $percent.'%');
$percent_length = $percent_dimensions[2] - $percent_dimensions[0];
ImageTTFText($im, $main_size, 0, $width-$percent_length-$text_indent,
$y+($bar_height/2), $percent_color, $fontname, $percent.'%');

if ($total_votes > 0)
$right_value = intval(round(($row->num_votes/$total_votes)*100));
else
$right_value = 0;

// length of bar for this value
$bar_length = $x + ($right_value * $bar_unit);

// draw bar for this value
ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);

// draw title for this value
ImageTTFText($im, $main_size, 0, $text_indent, $y+($bar_height/2),
$text_color, $fontname, "$row->candidate");

// draw outline showing 100%
ImageRectangle($im, $bar_length+1, $y-2,
($x+(100*$bar_unit)), $y+$bar_height, $line_color);

// display numbers
ImageTTFText($im, $small_size, 0, $x+(100*$bar_unit)-50, $y+($bar_height/2),
$number_color, $fontname, $row->num_votes.'/'.$total_votes);

// move down to next bar
$y=$y+($bar_height+$bar_spacing);

I've exhausted every idea I have to figure out the problem. Can anyone point me in the right direction? Is there another option for setting the font?

Thanks in advance.

maccas

8:19 pm on Dec 3, 2005 (gmt 0)

10+ Year Member



This is a bit of my script that works.

$font= 'C:\webpages\uk\maps\verdref.ttf';
imagettftext($image, 7, 0, $amountstring+5, $amountdown+3, $black, $font, $town);

Sorry should of read your error, try and upload the font to your server and then set the font at

$fontname = '/hsphere/local/home/#*$!/#*$!.com/verdana.tff';

EJCrew

8:36 pm on Dec 3, 2005 (gmt 0)

10+ Year Member



Thank you, maccas. I had uploaded the font to my server but was not using the /hsphere location. The font works now (I just have to solve my mysql problems, sigh).