Page 1 of 1

argh imageTTFtext problem

Posted: Sun Apr 27, 2003 3:39 pm
by toms100
ok here is my script working:
http://www.saundersbc.f2s.com/stat.php?UN=gurlen_borg
Image
you can change UN to any runescape username (if you know what that is)
anyway
when it generates the image it does the text on different lines for some reason!
here is my image code:

Code: Select all

<?php
function drawStat($rank,$xp, $x = 300, $y = 30) {
header("Content-type: image/png");
$image = imagecreate($x,$y);
$fontsize = 12;
$font = "/web/sites/296/saundersbc/www.saundersbc.f2s.com/font.ttf";
$blue = imagecolorallocate($image, 0,0,255);
$white = imagecolorallocate($image, 255,255,255);
imagefill($image, 0, 199, $white);
$text = "Rank: $rank TotalXP: $xp";
imageTTFtext( $image, $fontsize, 0,2,18, $blue, $font, $text);

imagejpeg($image);
}
?>
i hope someone can help
this is driving me mad :twisted:

Posted: Sun Apr 27, 2003 5:17 pm
by []InTeR[]
Maybe there are some \n's or \r's in the vars?

Posted: Mon Apr 28, 2003 2:57 am
by toms100
yes i think your right, if i put in the values by typing it comes out fine..
well heres the rest of my script which must be causing the problem

Code: Select all

<?php
function getstats($username) {
$webpage = "http://www.runescape.com/hiscoreuser.cgi?category=0&username=".$username;
$fp = fopen( $webpage, "r" ) or die("couldnt open $webpage");
$page = explode(' ', implode('', file($webpage)) ); // split it into words
$word = count($page);
$i = 0;
while ($i <= $word) { 
	$temp = str_replace( '<', '.', $page[$i] );
	$temp = str_replace( '>', '.', $temp );
	$temp = str_replace( ' ', '', $temp );
	$pg = explode('.',$temp);
	$o = 0;
	$todo = count($pg);
	while ( $o <= $todo ) {
		if ( $pg[$o] == "color=yellow" ) {
			
			/// i know the next value will be rank
			if (isset($s)){
				$xp = str_replace('\r', '',$pg[$o+1] );
				$xp = str_replace('\n', '',$xp );
				print "$xp<br>";
				}
			else {
				$rank = str_replace('\r', '',$pg[$o+1] );
				$rank = str_replace('\n', '',$rank );
				print "$rank<br>";
				$s = 1;
			}
			/// etc..		
			}
		$o++;
	}
	$i++;	
}
$GLOBALS['rank'] = $rank;
$GLOBALS['xp'] = $xp;
}
?>

Posted: Mon Apr 28, 2003 3:16 am
by []InTeR[]
Can you parse

var_dump($text);

Just before imageTTFtext.

Then you can see if you have some enters in it.

Posted: Mon Apr 28, 2003 4:04 am
by toms100
i did the var_dump
and $xp ends up as
їcode]
string(8) " 4863750"
and $rank ends up as:
string(5) " 5323"
ї/code]

Posted: Mon Apr 28, 2003 4:06 am
by toms100
YAY I GOT IT TO WORK:)
i noticed there was whitespace at the begging so i trimed the variables and it worked!!!!
thanks for the suggestions:)