<?php
class xfire_sig{
    var 
$username;
    var 
$format;
    var 
$img;
    var 
$textcolor;
    var 
$fontsize;
    var 
$font;
    var 
$masterx;
    var 
$mastery;
    var 
$defaultcolor;
    
    function 
xfire_sig($user=NULL){
        
$this->username $user;
        if(
$user == NULL){
            
$this->error('No username entered');
        }
    }
    function 
headers(){
        switch (
$this->format){
            case 
'jpg':
            
header("Content-type: image/jpg");
            break;
            case 
'gif':
            
header("Content-type: image/gif");
            break;
            case 
'png':
            default:
            
header("Content-type: image/png");
            break;
        }
        @
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        @
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
        @
header("Cache-Control: no-store, no-cache, must-revalidate");
        @
header("Cache-Control: post-check=0, pre-check=0"false);
        @
header("Pragma: no-cache");
    }

    function 
loadImage($file 'base.png'){
        if(!
file_exists($file)){
            
$this->error('No base file uploaded');
        }
        
$this->img imagecreatefrompng($file);
    }
    function 
hex2rgb($hex){
        if (
=== strpos($hex'#')){
        
$hex substr($hex1);
        }elseif (
=== strpos($hex'&H')){
        
$hex substr($hex2);
        }
        
$cutpoint ceil(strlen($hex) / 2)-1;
        
$rgb explode(':'wordwrap($hex$cutpoint':'$cutpoint), 3);
        
$rgb[0] = (isset($rgb[0]) ? hexdec($rgb[0]) : 0);
        
$rgb[1] = (isset($rgb[1]) ? hexdec($rgb[1]) : 0);
        
$rgb[2] = (isset($rgb[2]) ? hexdec($rgb[2]) : 0);
        return 
$rgb;
    }
    function 
setColor($hex){
    if(
strlen($hex) != && strlen($hex) != 7)
        
$hex $this->defaultcolor;
    
$temp $this->hex2rgb($hex);
    
$this->textcolor imagecolorallocate($this->img$temp[0], $temp[1], $temp[2]);
    }
    function 
addText($text,$x,$y,$color NULL){
        if(
$color!=NULL){
            
$this->setColor($color);
        }else{
            
$this->setColor($this->defaultcolor);
        }
        
$box imagettfbbox $this->fontsize0$this->font$text );
        
$height $this->fontsize+2;
        
imagettftext($this->img$this->fontsize0$x+$this->masterx$y+$this->mastery+$height$this->textcolor$this->font$text);
    }
    function 
addIcon($icon,$x,$y,$type='gif',$xfire=true){
        if(
$xfire==true){
        
$icon 'http://media.xfire.com/xfire/xf/images/icons/'.$icon.'.gif';
        }
        switch(
$type){
            case 
'png':
                
$icon = @imagecreatefrompng($icon);
            break;
            case 
'jpg':
                
$icon = @imagecreatefromjpeg($icon);
            break;
            case 
'gif':
            default:
                
$icon = @imagecreatefromgif($icon);
            break;
        }
        @
imagecopymerge($this->img$icon,    $x+$this->masterx,    $y+$this->mastery,    00imagesx($icon), imagesy($icon), 100 ); 
    }
    function 
displayImage(){
        switch (
$this->format){
            case 
'jpg':
            
imagejpeg($this->img,NULL,95);
            break;
            case 
'gif':
            
imagesavealpha$this->imgtrue );
            
imagegif($this->img);
            break;
            case 
'png':
            default:
            
imagesavealpha$this->imgtrue );
            
imagepng($this->img);
            break;
        }
    }
    function 
formatTime($time){
        
$this->hours = (int)($time/3600);
        return (
$this->hours == 0) ? (($time == 0) ? '0 hrs':'< 1 hr'): (($this->hours == 1)? '1 hr'$this->hours.' hrs') ;
    }
    function 
transparent($transparentcolor){
        
$transparent1 $this->hex2rgb($transparentcolor);
        
$transparent2 imagecolorallocate($this->img$transparent1[0], $transparent1[1], $transparent1[2]); // Set the transparent colour to black
        
imagecolortransparent ($this->img,$transparent2); // Make the transparent colour transparent
    
}
    function 
error($msg){
        
$this->format 'png';
        
$this->headers();
        
$this->img = @imagecreate(30020);
        
$background_color imagecolorallocate($this->img0,00);
        
$text_color imagecolorallocate($this->img25500);
        
imagestring($this->img222,  "Error: "$msg$text_color);
        
imagepng($this->img);
        
imagedestroy($this->img);
        die();
    }
}
?>