SRL Archive - Web Development

[PHP] Can't use ImageTTFText();


Eduard

2013-01-04 20:02:53

Hi guys,

i'm trying to create my dynamic signature. Everything went well except for the fact that I cannot use ImageTTFText();

Temoporarily I use Imagestring(); atm. This is the result:

http://puu.sh/1JDNv


My problem:

This is my source code:


<?PHP
header('Content-Disposition: filename=sig.png');
header('Content-Type: image/png');
function formatMilliseconds($milliseconds) {
$seconds = floor($milliseconds / 1000);
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = floor($hours / 24);
$milliseconds = $milliseconds % 1000;
$seconds = $seconds % 60;
$minutes = $minutes % 60;
$hours = $hours % 24;

if($days == 0){
$format = ' %uH %02uM %02uS';
$time = sprintf($format, $hours, $minutes, $seconds);
return rtrim($time, '0');
}else{
$format = '%uD %uH %02uM %02uS';
$time = sprintf($format, $days, $hours, $minutes, $seconds);
return rtrim($time, '0');
}

}


$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);


if ($db_found) {

$SQL = "SELECT * FROM table1 WHERE ID=1";
$result = mysql_query($SQL);
if($result){
while ($db_field = mysql_fetch_assoc($result)){

$xp = $db_field['XP'];
$time = $db_field['Time'];
$logs = $db_field['Logs'];
}



$image = 'sig.png';
$img = imagecreatefrompng($image);


$main_color = imagecolorallocate($img, 63, 55, 18);
// putenv('GDFONTPATH=' . realpath('.'));

// imagettftext ($img ,10,0,160,80, $main_color ,"public_html/arialblack.ttf", "imagettftexttest")
imagestring($img ,5,160, 80,number_format($xp),$main_color);
imagestring($img ,5,180 , 115,formatMilliseconds($time * 1000),$main_color);
imagestring($img, 5,205,150,number_format($logs),$main_color);
imagestring($img, 5,125,190,'Coming soon..',$main_color);





imagepng($img);
imagedestroy($img);
}else
print "False";

}
else
print "DB not Found, please report this";


?>


the important section is this:


putenv('GDFONTPATH=' . realpath('.'));

imagettftext ($img ,10,0,160,80, $main_color ,"public_html/arialblack.ttf", "imagettftexttest")


whenever I run this piece of code this error pops up:

http://puu.sh/1JDQP


Anybody knows what the problem could be? i really would like to use ImageTTfText(); for a nicer font.

xtrapsp

2013-01-04 21:31:01

well line 58 is blank for me weirdly.

It's 2:30 am here, but I was thinking, you know you can still use custom fonts the other way right?

Eduard

2013-01-05 10:46:39

From: xtrapsp
well line 58 is blank for me weirdly.

It's 2:30 am here, but I was thinking, you know you can still use custom fonts the other way right?


I think line 58 is blank because I deleted the username/password lines.

Could u please elaborate on how to? I can't find anything on it and i'm quite stuck on how to do this.

xtrapsp

2013-01-05 12:21:25

Look in my signature for the 'updated' tutorial