All pastes #905923 Raw Edit

Someone

public text v1 · immutable
·published 2008-02-16 03:38 UTC
rendered paste body
<?PHP

    /*
    Class: h3sigs
    */

        class h3sig {
            
            /*
            Group: variables
            */
            
                var $bg_dir = "backgrounds";
                var $font_dir = "fonts";

            /*
            Group: loaders
            */
    
                /*
                Function: __construct
                Description: Loaded when the class is initialized. Creates the signatures.
                */
        
                    function __construct($gamertag, $background) {
    
                        header("Content-Type: image/gif");
                        include "../../../global/func.php";
        
                        if (!$this->valid_gamertag($gamertag))
                            $this->error_sig("Gamertag is invalid.");
                        if (!file_exists("{$this->bg_dir}/{$background}.gif"))
                            $this->error_sig("The background you supplied doesn't exist.");
    
                        $this->create_sig($gamertag, $background);
            
                    } // function.__construct
                    
            /*
            Group: generators
            */
            
                /*
                Function: create_sig
                Description: Creates a Halo 3 signature.
                */
                
                    function create_sig ($gamertag, $background) {
                        
                        $im     = imagecreatefromgif("{$this->bg_dir}/{$background}.gif");

                        $white  = imagecolorallocate($im, 240, 240, 240);
                        $black  = imagecolorallocate($im,   0,   0,   0);
                        
                        $width  = imagesx($im);
                        $height = imagesy($im);
    
                        $pdata  = pxml($gamertag);

                        imagettftext($im, 20, 0, 17, 41, $black, "fonts/segoe.ttf", $gamertag);
                        imagettftext($im, 20, 0, 16, 40, $white, "fonts/segoe.ttf", $gamertag);
    
                        $pdata = array(
                            "Service Tag"   => $pdata->calltag,
                            "Rank"          => $pdata->rank,
                            "Highest Skill" => $pdata->highestSkill,
                            "Experience"    => $pdata->experience,
                            "KD Ratio"      => $pdata->ranked->kDRatio,
                        );

                        $cx     = 21;
                        $cy     = 70;
    
                        foreach( $pdata as $label => $value ) {
                            imagettftext($im, 11, 0, $cx+1, $cy+1, $black, "fonts/candara.ttf", "{$label}: {$value}");
                            imagettftext($im, 11, 0, $cx,   $cy,   $white, "fonts/candara.ttf", "{$label}: {$value}");
                            $cy += 15;
                        }
    
                        imagegif($im);
                        imagedestroy($im);
    
                        
                    } // function.create_sig
                    
                /*
                Function: error_sig
                Description: Creates a plain image to show an error has been encountered.
                */
                
                    function error_sig ($message) {
    
                        $im    = imagecreate(400, 150);
    
                        $black = imagecolorallocate($im,   0,   0,   0);
                        $white = imagecolorallocate($im, 255, 255, 255);

                        imagefill($im, 1, 1, $white);
                        imagettftext($im, 11, 0, 15, 27, $black, "fonts/segoe.ttf", wordwrap($message, 50, "\n", True));
                        
                        imagegif($im);
                        imagedestroy($im);
    
                        die();
                        
                    } //function.error_sig
                    
            /*
            Group: validators
            */
    
                /*
                Function: valid_gamertag
                Description: Finds if $gamertag is valid
                */
        
                    function valid_gamertag($gamertag) {
    
                        if (preg_match("/^[a-zA-Z0-9\ ]+$/u", $gamertag)) {
                            return True;
                        } else {
                            return 0;
                        }
    
                    } // function.valid_gamertag
    
        } // h3sig.class

    if (isset($_GET['gamertag']) && isset($_GET['background']))
         new h3sig($_GET['gamertag'], $_GET['background']);
    else die("Sneaky devil");

?>