1 Replies - 7291 Views - Last Post: 19 April 2009 - 03:57 PM Rate Topic: -----

#1 deedee66   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 21-September 08

Font error - don't understand

Post icon  Posted 19 April 2009 - 03:46 PM

I keep getting the following error message when trying to run the following program. And I don't understand why.

Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 97

Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 103

Warning: Wrong parameter count for imagettfbbox() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 121

Notice: Undefined variable: percent_length in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 123

Warning: Wrong parameter count for imagettftext() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 124

Notice: Undefined variable: text_ident in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 133

Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 134

Notice: Use of undefined constant bar_unit - assumed 'bar_unit' in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 137

Notice: Use of undefined constant bar_height - assumed 'bar_height' in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 137

Warning: Wrong parameter count for imagettftext() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 140

Warning: Wrong parameter count for imagettfbbox() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 121

Notice: Undefined variable: percent_length in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 123

Warning: Wrong parameter count for imagettftext() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 124

Notice: Undefined variable: text_ident in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 133

Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 134

Notice: Use of undefined constant bar_unit - assumed 'bar_unit' in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 137

Notice: Use of undefined constant bar_height - assumed 'bar_height' in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 137

Warning: Wrong parameter count for imagettftext() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 140

Warning: Wrong parameter count for imagettfbbox() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 121

Notice: Undefined variable: percent_length in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 123

Warning: Wrong parameter count for imagettftext() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 124

Notice: Undefined variable: text_ident in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 133

Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 134

Notice: Use of undefined constant bar_unit - assumed 'bar_unit' in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 137

Notice: Use of undefined constant bar_height - assumed 'bar_height' in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 137

Warning: Wrong parameter count for imagettftext() in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 140

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php:137) in C:\Program Files\Apache Group\Apache2\htdocs\show_poll.php on line 149
PNG  IHDRIDATxm1@QNܙՙs=0^Ā] Yko13 'A$A$A$A$A$A$A$A$A$A$A$A$A$A$A$A$A$A$A$A$A$w qz[email protected]'3޷G zܞ;b"cmW??nPw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw q3&g036w qw qw qw qw qw qw qw qz[email protected]9G?$G?ugcN/sdm_k~9ɼPw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw qw q3&g036w qw qw qw qw qw qw qw qfk;@9P;@;@;@;@;@;@;@;@;@;@;@;@;@;@;@;@;@;@;@Zk}{q3;@;@1ަC H H H H H^o29zIENDB`




html code
<html>
<head>
	<title>Polling</title>
<head>
<body>
<h1>Pop Poll</h1>
<p>Who will you vote for in the election?</p>
<form method="post" action="show_poll.php">
<input type="radio" name="vote" value="John Smith">John Smith<br />
<input type="radio" name="vote" value="Mary Jones">Mary Jones<br />
<input type="radio" name="vote" value="Fred Bloggs">Fred Bloggs<br /><br />
<input type="Submit" value="Show results">
</form>
</body>
</html>





php code
<?php
/**********************
Database query to get poll info
***********************/

//get vote from form
$vote=$_REQUEST['vote'];

// log in to database
if (!$db_conn = new mysqli('localhost', 'poll', 'poll', 'poll'))
{
	echo 'Could not connect to db<br />';
	exit;
}

if (!empty($vote)) // if they filled the form out, add their vote
{
	$vote = addslashes($vote);
	$query = "update poll_results
		set num_votes = num_votes + 1
		where candidate = '$vote'";
	if(!($result = @$db_conn->query($query)))
	{
		echo 'Could not connect to db<br />';
		exit;
	}
}

// get current results fo poll, regardless of whether they voted
$query = 'select * from poll_results';
if(!($result = @$db_conn->query($query)))
{
	echo 'Could not connect to the db<br />';
	exit;
}
$num_candidates = $result->num_rows;

//calculate total number of votes so far
$total_votes=0;
while ($row = $result->fetch_object())
{
	$total_votes += $row->num_votes;
}
$result->data_seek(0); // reset result pointer

/*****************************************
	Initial calculations for graph
*****************************************/

// set up constants
putenv('GDFONTPATH=C:\C:\WINDOW\Fonts');
$width=500;   //width of image in pixels - this will fit in 640x480
$left_margin = 50;  //space to leave on left of graph
$right_margin= 50; // ditto right
$bar_height = 40;
$bar_spacing = $bar_height/2;
$font = 'Arial';
$title_size= 16; // point
$main_size= 12; // point
$small_size=12; //point
$text_indent = 10; // position for text labels form edge of image

// set up initial point to draw from
$x = $left_margin + 60; // place to draw baseline of the graph
$y = 50;
$bar_unit = ($width-($x+$right_margin)) / 100;  // one "point" on the graph

// calculate height of graph - bars plus gaps some margin
$height = $num_candidates * ($bar_height + $bar_spacing) + 50;

/*********************************************************
	Setup base image
*********************************************************/
// create a blank canvas
$im = imagecreatetruecolor($width, $height);

// Allocate colors
$white=imagecolorallocate($im, 255, 255, 255);
$blue=imagecolorallocate($im, 0, 64, 128);
$black=imagecolorallocate($im, 0, 0, 0);
$pink = imagecolorallocate($im, 255, 78, 243);

$text_color = $black;
$percent_color = $black;
$bg_color = $white;
$line_color = $black;
$bar_color = $blue;
$number_color = $pink;

// create "canvas" to draw on
imagefilledrectangle($im, 0, 0, $width, $height, $bg_color);
// draw outline around canvas
imagerectangle($im,0,0,$width-1, $height-1, $line_color);

//Add title
$title = 'Poll Results';
$title_dimensions = imagettfbbox($title_size,0,$font, $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, $font, $title);

// Draw a base line form a little above first bar location
// to 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 = $result->fetch_object())
{
	if ($total_votes > 0)
		$percent = intval(($row->num_votes/$total_votes)*100);
	else
		$percent = 0;
		
// display percent for this value
$percent_dimensions = imagettfbbox($main_size, 0, $font, $percent, '%');
$percent_lenght = $percent_dimensions[2] - $percent_dimensions[0];
imagettftext($im, $main_size, 0, $width-$percent_length-$text_indent,
		$y+($bar_height/2), $percent_color, $font, $percent, '%');
		
//length of bar for this value
$bar_length = $x + ($percent * $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_ident, $y+($bar_height/2),
			$text_color, $font, "$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, $font, $row->num_votes.'/', $total_votes);

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

/**************************************************************
	Display image
***************************************************************/
Header('Content-type: image/png');
imagepng($im);

/**************************************************************
	clean up
**************************************************************/
imagedestroy($im);
?>



Is This A Good Question/Topic? 0
  • +

Replies To: Font error - don't understand

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5554
  • View blog
  • Posts: 14,560
  • Joined: 18-April 07

Re: Font error - don't understand

Posted 19 April 2009 - 03:57 PM

GDFontPath is a bit buggy on Windows but one thing I also notice is that GDFONTPATH=C:\C:\WINDOW\Fonts has two C:\ in the path. That would be the first problem.

See if that first fixes it. Next would be to make a copy of the font file and paste it into the directory where your script is. Then use realpath() to try and load it. Or you could try a sub folder like realpath('./font/'). This says get the real path and go into the font sub folder.

:)

PS... also your last error is related to your header() function call. If your code outputs ANYTHING, even a space, it will send the headers itself and result in an error when you try to send headers using header() later. (since they have already been sent).

So try and make sure that you are not outputting anything before you call that function.

This post has been edited by Martyr2: 19 April 2009 - 03:59 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1