Make Your Own Stats Sigs!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Durinthiam
    Member
    • Mar 2010
    • 9

    #1

    Make Your Own Stats Sigs!

    Evenin all! I thought it about time that a fine tradition was restored, so I'm going to help all the clans and random people out there make their own stat sigs using PHP and BFBCS.com's API (if/when EA release, or someone finds EA's then I will redo).

    We'll start off with what's included by BFBCS. Click Here to read it all

    I'm just going to grab 1ApRiL's example code first
    [PHP]<?php
    $url = 'http://api.bfbcs.com/api/pc';
    $postdata = 'players=1ApRiL&fields=all';

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    $data = curl_exec($ch);
    curl_close($ch);

    $data = json_decode($data,true);

    print_r($data);

    ?> [/PHP]

    Now, for now we're just going to call up one player and the general info. If you want to get into using variables for different names, you can wait until I release my v1 script or have a rummage on tinterwebs for the mass of tutorials

    [PHP]<?php
    $url = 'http://api.bfbcs.com/api/pc';
    $postdata = 'players=1ApRiL&fields=general'; //taken second player name away and changed fields to general

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    $data = curl_exec($ch);
    curl_close($ch);

    $data = json_decode($data); //Removed ,true from the boolean

    //Notice I've got rid of print_r($data);

    [/PHP]

    First we set the image background. I'll be using one I quickly whipped up

    [PHP]
    $im = imagecreatefrompng("./basic.png") or die("Cannot Initialize new GD image stream");
    [/PHP]

    now we'll get the info into data that can be used in PHP
    [PHP]
    //Get basic player info into useable bits
    foreach ( $data->players as $player ) { //Get "players" array from $data and set individually as $player to take info for each object within the array
    $name = "{$player->name}";
    $rank_title = "{$player->rank_name}";
    $kills = "{$player->kills}";
    $deaths = "{$player->deaths}";
    $score = "{$player->score}";
    $dogtags = "{$player->general->dogt}";

    } // Close Foreach

    [/PHP]

    Now to set some simple ones, your clan tag and clan name
    [PHP]
    //User Set Variables
    $clan_tag = "=22ND=";
    $clan_name = "THE 22ND REGIMENT";
    [/PHP]

    Now to setup fonts and colours. I actually have Eurostile but there's a good free lookalike called Waukogen LDO which you can get Here. I use 3 styles, bold extended, extended and normal bold. Rename them to the same as below, all lowercase, no special characters or spaces and put in same folder as your php file
    [PHP]
    //Fonts
    $font = "euro.ttf";
    $font_bold = "eurobold.ttf";
    $details_bold = "eurobold2.ttf";
    //Colours ($im, RED, GREEN, BLUE) 0-255 range for each
    $background_color = imagecolorallocate($im, 135, 156, 165);
    $border = imagecolorallocate($im, 0, 0, 0); // black
    $red = imagecolorallocate($im, 255, 108, 0); // Red
    $grey = imagecolorallocate($im, 183, 183, 183); // Grey
    $lightgrey = imagecolorallocate($im, 253, 253, 253); // Light Grey

    imagerectangle ($im, 0, 0, 399, 99, $border); //Draw Border around image
    [/PHP]
    Now we'll do the clantag, name and rank title beneath and clan name on the right side
    [PHP]
    // ($im, FONTSIZE, XAXIS, YAXIS, STRING, COLOUR);
    imagestringup($im, 1, 389, 90, $clan_name, $grey);
    imagettftext ($im, 12, 0, 10, 20, $red, $font_bold, $clan_tag.$name); //Clantag and Name in red, size 12, bold
    imagettftext ($im, 7, 0, 10, 30, $lightgrey, $font, $rank_title); //Rank Title in light grey, size 11, normal
    [/PHP]

    Now we'll actually get some stats on the go!

    [PHP]
    //Total Score
    imagettftext ($im, 7, 0, 10, 50, $lightgrey, $details_bold, "SCORE:"); //The title
    imagettftext ($im, 7, 0, 75, 50, $lightgrey, $font, $score); //the stat

    //Kills
    imagettftext ($im, 7, 0, 10, 60, $lightgrey, $details_bold, "KILLS:");
    imagettftext ($im, 7, 0, 75, 60, $lightgrey, $font, $kills);

    //Deaths
    imagettftext ($im, 7, 0, 10, 70, $lightgrey, $details_bold, "DEATHS:");
    imagettftext ($im, 7, 0, 75, 70, $lightgrey, $font, $deaths);

    //Dogtags
    imagettftext ($im, 7, 0, 200, 50, $lightgrey, $details_bold, "DOGTAGS:");
    imagettftext ($im, 7, 0, 275, 50, $lightgrey, $font, $dogtags);
    [/PHP]

    UPDATE 27/03/10 @ 22:07 GMT

    Now we'll add a rank image in the right hand corner (like my own signature) by taking the base image (which co-incidently is a lovely size to make stat-linked rank avatars ) resizing it, and adding it to the sig. Because I'm a generous chap, I'll even give you all of the rank images in one handy .rar file! Download Here. They will extract to /ranks/ so no need to make a new folder.

    and now for the code!

    [php]
    $rank_image = imagecreatefrompng("./ranks/r0{$player->rank}.png");
    $insert_x = imagesx($rank_image); //fetches images width
    $insert_y = imagesy($rank_image); //fetches images height
    $new_width = round($insert_x*0.7); //resizes to 70% of original
    $new_height = round($insert_y*0.7); // ^^
    $rank_image = imagecopyresized($im,$rank_image, 320, 15, 0, 0, $new_width, $new_height, $insert_x, $insert_y); //Inserts it into the base image at defined location (320 across, 15 down)
    [/php]



    close up the image and output it!
    [PHP]
    header("Content-type: image/png");
    imagepng($im); // Create the image


    ?>[/PHP]

    Now you should have something like this:


    Just by examining the code, you should easily be able to figure out how to grab other stats. Keep your eyes on this thread as I will update it with features (i'm currently mcgyvering rank images into my own sigs) and the release of my public version will go here too!

    For a nice to look at breakdown of everything available to grab, simply look here



    Contributions are welcome, as are problems but please post them up in here and not in my inbox :thumbsup:
  • Tampa
    Member
    • Feb 2010
    • 504

    #2
    Re: Make Your Own Stats Sigs!

    Thanks! Maybe sticky? +rep

    Comment

    • The_Eliminator
      Senior Member
      • Aug 2006
      • 5486

      #3
      Re: Make Your Own Stats Sigs!

      I agree sticky, +rep

      Comment

      • Durinthiam
        Member
        • Mar 2010
        • 9

        #4
        Re: Make Your Own Stats Sigs!

        Cheers guys! Working on pulling some images in to it now, will update soon :)

        Comment

        • Durinthiam
          Member
          • Mar 2010
          • 9

          #5
          Re: Make Your Own Stats Sigs!

          Updated with rank images. Any questions, fire away!

          and oh! It's been stickym'fied

          Comment

          • messfeeder
            Member
            • Feb 2008
            • 616

            #6
            Re: Make Your Own Stats Sigs!

            I would do this if my stats didn't suck! LOL My CPU can't handle this game in MP. Too bad I don't have the money to upgrade for now.

            Comment

            • MurDuM
              Member
              • Jun 2010
              • 1

              #7
              Re: Make Your Own Stats Sigs!

              For some reason its not working.. I get this error:
              Code:
              Parse error: syntax error, unexpected $end in /home/teamrav/public_html/statsigs/bfsig.php on line 68
              Here is the URL: http://www.teamravage.x10.mx/statsigs/bfsig.php?

              This is how my code is on bfsig.php:

              Code:
              header("Content-type: image/png");
              imagepng($im); // Create the image
                      
                              ?>
              Can you please help me.

              Comment

              • Durinthiam
                Member
                • Mar 2010
                • 9

                #8
                Re: Make Your Own Stats Sigs!

                Originally posted by MurDuM
                For some reason its not working.. I get this error:
                Code:
                Parse error: syntax error, unexpected $end in /home/teamrav/public_html/statsigs/bfsig.php on line 68
                Here is the URL: http://www.teamravage.x10.mx/statsigs/bfsig.php?

                This is how my code is on bfsig.php:

                Code:
                header("Content-type: image/png");
                imagepng($im); // Create the image
                        
                                ?>

                Can you please help me.
                Post the whole code that you have used for me please buddy

                Comment

                Working...