basically this script draws the text in the wrong colour. it allways ends up being brown.... (RGB 104,76,52)
the script is passed the text correctly and does everything other than colour it correct!.
the function that needs attention is colourf.
somehow it is going wrong....
i pass "red" or "blue" or "FF00FF" as $colour in this script when constructed and it just will not colour!!!.
Code: Select all
<?php
class sig {
var $bg;
var $text;
var $username;
var $xOff;
var $yOff;
var $font;
var $fontsize;
var $fontcolour;
var $skill;
var $image;
function sig($bg,$text,$username,$xOff,$yOff,$font,$fontsize,$fontcolour,$skill) {
$this->bg = $bg;
$this->text = $text;
$this->username = str_replace(' ','_',$username);;
$this->xOff = $xOff;
$this->yOff = $yOff;
$this->font = "/web/sites/296/saundersbc/www.saundersbc.f2s.com/rs/fonts/".$font;
$this->fontsize = $fontsize;
$this->skill = $skill;
if ($this->bg == "") {
$this->bg = "sig2.jpg";
}
$ext = explode('.',$this->bg);
$th = count($ext);
//$ext[$th-1] should be the extension..
if ($ext[$th-1] == 'jpg' || $ext[$th-1] == 'JPG' || $ext[$th-1] == 'jpeg' || $ext[$th-1] == 'JPEG') {
$this->image = imagecreatefromjpeg($this->bg);
}
/*if ($ext[$th-1] == 'gif' || 'GIF') {
$this->image = imagecreatefromgif($this->bg);
}*/
if ($ext[$th-1] == 'png' || $ext[$th-1] == 'PNG') {
$this->image = imagecreatefrompng($this->bg);
}
$this->colourf($fontcolour);
$this->drawimage();
}
function hex2dec($input) {
if(strlen($input) < 6 ) return(false);
$r = hexdec(substr($input,0,2));
$b = hexdec(substr($input,2,2));
$g = hexdec(substr($input,4,2));
return("$r,$b,$g");
}
function colourf($colour) {
switch ($colour) {
case 'black':
$col = "000000";
break;
case 'white':
$col = "FFFFFF";
break;
case 'blue':
$col = "FF0000";
break;
case 'red':
$col = "00FF00";
break;
case 'green':
$col = "0000FF";
break;
case 'yellow':
$col = "FFFF00";
break;
case 'magenta':
$col = "FF00FF";
break;
case 'cyan':
$col = "00FFFF";
break;
case 'orange':
$col = "FFA500";
break;
case 'redorange':
$col = "FF4500";
break;
case 'violet':
$col = "EE82EE";
break;
case 'purple' :
$col = "A020F0";
break;
case 'greenblue':
$col = "2E8B57";
break;
default:
$col = $colour;
break;
}
$rgb = $this->hex2dec($col);
if ($rgb) {
$this->fontcolour = imagecolorallocate($this->image, $rgb['r'],$rgb['g'],$rgb['b']);
} else {
$this->fontcolour = imagecolorallocate($this->image, 0,0,0);
}
}
function drawimage() {
/// should have done the image now
/// get the stats
if ($this->skill == "random") {
$skill = rand(0,15);
settype($skill,"int");
$stats = $this->getstats($this->username,$skill);
$t = 0;
while ($stats['lvl'] = "" && $t < 10) {
$skill = rand(0,15);
settype($skill,"int");
$stats = $this->getstats($this->username,$skill);
$t++;
}
}
else{
$stats = $this->getstats($this->username,$this->skill);
}
if ($stats['xp'] == "") {
$txt = "xp is NULL";
}
else {
$txt = $this->textdo($this->username,$stats['lvl'],$stats['rank'],$stats['skill'],$stats['xp']);
}
$lines = explode('\n',$txt);
$this->writetxt($this->xOff,$this->yOff,$lines);
imagejpeg($this->image);
}
function writetxt($x,$y,$lines) {
$cl = count($lines);
// $cl is the number of lines to draw.
//loop thru each line and draw.
$y = ($y + $this->fontsize);
$lin = 0;
while ($lin < $cl) {
imagettftext( $this->image, $this->fontsize, 0,$x,$y, $this->fontcolour, $this->font, $lines[$lin]);
$y = $y + $this->fontsize + 2;
$lin++;
}
}
function textdo($username,$lvl,$rank,$skill,$xp) {
$txt = trim($this->text);
$txt = str_replace('@USERNAME',$username,$txt);
$txt = str_replace('@LVL',$lvl,$txt);
$txt = str_replace('@RANK',$rank,$txt);
$txt = str_replace('@SKILL',$skill,$txt);
$txt = str_replace('@XP',$xp,$txt);
return $txt;
}
function getstats($username,$category=0) {
$webpage = "http://www.runescape.com/hiscoreuser.cgi?category=".$category."&username=".$username;
$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 ) {
//echo $pg[$o]."<br>";
if ( $pg[$o] == "color=yellow" ) {
/// i know the next value will be rank
switch ($s) {
case 1 :
$name = str_replace('\r', '',$pg[$o+1] );
$name = str_replace('\n', '',$name );
$s = 2;
break;
case 2:
$lvl = str_replace('\r', '',$pg[$o+1] );
$lvl = str_replace('\n', '',$lvl );
$s = 3;
break;
case 3:
$xp = str_replace('\r', '',$pg[$o+1] );
$xp = str_replace('\n', '',$xp );
break;
default:
$rank = str_replace('\r', '',$pg[$o+1] );
$rank = str_replace('\n', '',$rank );
$s = 1;
break;
}
}
if ($pg[$o] == "width=290" ) {
$skill = $pg[$o+5];
}
/// etc..
$o++;
}
$i++;
}
$got['rank'] = trim($rank);
$got['xp'] = trim($xp);
$got['lvl'] = trim($lvl);
$got['skill'] = trim($skill);
return $got;
}
}
?>Tom