Page 1 of 1

PHP, GD and ImageTTFText

Posted: Thu Dec 18, 2003 11:29 pm
by EricBrian
I am having problems with this code:

Code: Select all

<?
header("Content-type: image/jpeg"); 

// Get count for ALL from counter DB
$connection = mysql_connect("localhost","xxxxxxxxxxxx","xxxxxxxxxxxx") or die(mysql_error());
mysql_select_db("counter") or die (mysql_error());
$query = "SELECT num FROM counter WHERE page = 'All'"; 
$sql_query_result = mysql_query ($query,$connection);
$row = mysql_fetch_array ($sql_query_result); 
$text = $row&#1111;'num']." Visitors";
//Verified that $text returns "12345 Visitors" as expected

// Get image to manipulate & related info
$image_name     = "ericbrian_menu.jpg";
$im             = ImageCreateFromJpeg($image_name);
$color          = ImageColorAllocate($im, 255, 255, 255);
$fontfile       = "agencyr.ttf";

ImageTTFText($im,12,0,53,311,$color,$fontfile,$text); 
// $text returns "Visitors" and not "12345 Visitors"!
ImageJpeg($im);
ImageDestroy($im); // Destroy the buffer
?>
The code successfully retrieves the count and that is prepended to the string "Visitors." When I echo $text, it shows, as expected: 12345 Visitors.

However in this line:

Code: Select all

ImageTTFText($im,12,0,53,311,$color,$fontfile,$text);
only the word "Visitors" is displayed in the image and not "12345 Visitors."

Of course, the count 12345 is just there as a demostration.

Thanks,
Eric