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
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
First we set the image background. I'll be using one I quickly whipped up
now we'll get the info into data that can be used in PHP
Now to set some simple ones, your clan tag and clan name
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
Now we'll do the clantag, name and rank title beneath and clan name on the right side
Now we'll actually get some stats on the go!
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!
close up the image and output it!
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:
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 Code:
<?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 Code:
<?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 Code:
$im = imagecreatefrompng("./basic.png") or die("Cannot Initialize new GD image stream");
PHP Code:
//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 Code:
//User Set Variables
$clan_tag = "=22ND=";
$clan_name = "THE 22ND REGIMENT";
PHP Code:
//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 Code:
// ($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 Code:
//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);
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 Code:
$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)
close up the image and output it!
PHP Code:
header("Content-type: image/png");
imagepng($im); // Create the image
?>
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:
Comment