Code: Select all
class sig {
var $bg;
var $text;
var $username;
var $xOff;
var $yOff;
var $font;
var $fontsize;
var $fontcolour;
var $skill;
var $image;
var $im2;
var $r;
var $g;
var $b;
function workaround() {
$size = getimagesize($this->bg);
$this->image = imagecreate($size[0],$size[1]);
//make it transparent
$black = imagecolorallocate($this->image, 0, 0, 0);
imagefill($this->image,0,0,$black);
imagecolortransparent($this->image,$black);
//transparent
//return
}
function workaround2() {
/// copys it back
$size = getimagesize($this->bg);
imagecopymerge( $this->image, $this->image,0, 0,0,0, $size[0],$size[1],100);
}
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;
/// work around
$size = getimagesize($this->bg);
///
if ($this->bg == "") {
$this->bg = "sig2.jpg";
}
#$this->workaround();
$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 = imagecreate($size[0],$size[1]);
}
/*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);
$return_var = array(
'r' => hexdec(substr($input,0,2)),
'b' => hexdec(substr($input,2,2)),
'g' => hexdec(substr($input,4,2)));
return $return_var;
}
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->r = $rgb['r'];
$this->g = $rgb['g'];
$this->b = $rgb['b'];
} else {
$this->r = 0;
$this->g = 0;
$this->b = 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);
/// workaround
///$this->workaround2();
/// workaround^^
imagepng($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) {
$fontc = imagecolorallocate($this->image,$this->r,$this->g,$this->b);
imagettftext( $this->image, $this->fontsize, 0,$x,$y, $fontc, $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;
}
thats the class...
but i have been trying for months to get this to work under GD, and i ALLWAYS get the same problem with the font colour
bloody annoying tbh.