You are not logged in.
#1 18 Jul 2006 9:20 am
Battlefield2 avatar
I've added some mod_rewrite rules to the site to make the avatar images bbocde friendly:
Code:
http://www.sanity-free.org/bf2rank/?nick=[oink]_madhatter&score
can now be written this way:
Code:
http://www.sanity-free.org/avatar/nick/[oink]_madhatter/score.jpg
or if you're using your player id:
Code:
http://www.sanity-free.org/avatar/pid/45647367/score.jpg
adding score, delta and no text is as simple as the adding that text to the name of the image:
score.jpg, score_delta.jpg, score_delta_notext.jpg, and delta_notext.jpg (each word being seperated by an underscore)
note that no_text is notext when used in the image name: notext.jpg
for those interested in the mod rewrite rules for the .htaccess file here they are:
Code:
RewriteEngine On RewriteRule ^avatar/nick/([^/]*)/score\.jpg$ /bf2rank/index.php?nick=$1&score [L] RewriteRule ^avatar/nick/([^/]*)/score_delta\.jpg$ /bf2rank/?nick=$1&score&delta [L] RewriteRule ^avatar/nick/([^/]*)/delta_score\.jpg$ /bf2rank/?nick=$1&score&delta [L] RewriteRule ^avatar/nick/([^/]*)/score_notext\.jpg$ /bf2rank/?nick=$1&score&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_score\.jpg$ /bf2rank/?nick=$1&score&no_text [L] RewriteRule ^avatar/nick/([^/]*)/score_delta_notext\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/delta_score_notext\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_score_delta\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_delta_score\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/delta\.jpg$ /bf2rank/index.php?nick=$1&delta [L] RewriteRule ^avatar/nick/([^/]*)/notext\.jpg$ /bf2rank/?nick=$1&no_text [L] RewriteRule ^avatar/nick/([^/]*)/delta_notext\.jpg$ /bf2rank/?nick=$1&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_delta\.jpg$ /bf2rank/?nick=$1&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/score\.jpg$ /bf2rank/index.php?pid=$1&score [L] RewriteRule ^avatar/pid/([^/]*)/score_delta\.jpg$ /bf2rank/?pid=$1&score&delta [L] RewriteRule ^avatar/pid/([^/]*)/delta_score\.jpg$ /bf2rank/?pid=$1&score&delta [L] RewriteRule ^avatar/pid/([^/]*)/score_notext\.jpg$ /bf2rank/?pid=$1&score&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_score\.jpg$ /bf2rank/?pid=$1&score&no_text [L] RewriteRule ^avatar/pid/([^/]*)/score_delta_notext\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/delta_score_notext\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_score_delta\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_delta_score\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/delta\.jpg$ /bf2rank/index.php?pid=$1&delta [L] RewriteRule ^avatar/pid/([^/]*)/notext\.jpg$ /bf2rank/?pid=$1&no_text [L] RewriteRule ^avatar/pid/([^/]*)/delta_notext\.jpg$ /bf2rank/?pid=$1&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_delta\.jpg$ /bf2rank/?pid=$1&delta&no_text [L]
Offline
#2 16 Aug 2006 12:18 pm
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Just out of curiosity, is there an image that gives out in-game name and last date played?
Offline
#3 16 Aug 2006 12:57 pm
Re: Battlefield2 avatar
not as such. for the avatar, adding a name had too many possibilities for overflow (the name being longer than the image was wide), so I dint put it on there. the last date played also poses problems (minor though they may be). we use dd/mm/yyyy, others use mm/dd/yyyy, and there would need to be a way to format that date.
if you do a mock up in photoshop of an image, I'll put the code behind it. keep in mind if you use a particular font thats not standard, you'll need to send it to me, or show me where to get it (and php cant render the text like photoshop can).
Offline
#4 16 Aug 2006 3:45 pm
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Ok, little of this and little of that, came up with this simplistic but sexy (and not to busy) thingy, its 400 wide and 150 tall.
Code:
http://www.bamboocommandos.com/prank/images/expanded_info.png
Basically just need nickname and last played date thingy on it, feel free to throw onto it whatever you want
Offline
#6 17 Aug 2006 3:52 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Ok, so I basically write the stuff on it? Will do! Loving those new forum icons btw
Offline
#7 17 Aug 2006 4:59 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Ok, filled in some stuff there now:
Text is bold Times New Roman. If you can make it like the avatar thingy, like the one above, so I basically just write the url and the nick, no submit button this time, that would be great .
Last edited by Butcher (19 Aug 2006 6:59 am)
Offline
#8 21 Aug 2006 4:50 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Btw, noticed an image in the banner ontop of the site, an alley that looked a lot like the ones in Venice, you been to Venice too?
Offline
#9 21 Aug 2006 7:15 am
Re: Battlefield2 avatar
hehe nope (unfortunately I havent ventured too far out of texas). I got it off of a stock photography site: http://sxc.hu
Offline
#10 21 Aug 2006 10:13 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Ahh, ok. You should go there , beatiful city, beatiful girls, superb food and cheap living. Been there twice
Last edited by Butcher (21 Aug 2006 10:15 am)
Offline
#11 21 Aug 2006 12:13 pm
Re: Battlefield2 avatar
hehe, my son cant take 5 minute rides to the market, let alone a 10+ hour filght over seas. one of these days we'll get out around the world.
sorry I've been swamped and havent looked at doing the sig till just now. I'm not sure how to do the total time played thing (kind of unsure how to format that since EA just sends a date time stamp, so my code may be wrong there).
if thats looks ok, I'll post the code for it.
Offline
#12 21 Aug 2006 2:09 pm
#13 21 Aug 2006 2:14 pm
Re: Battlefield2 avatar
since the base image is a png, I work w/ it as a png and send it back out as a png.
create a new file (in the same directory as index.php in your prank folder) named image.php. add the following contents and upload or save on the server (dont copy the "Code:" text, just everything starting w/ "<?php" on):
Code:
<?php if($_GET['nick']) { include("bf2/bf2_player.php"); include("globals.php"); $bf2_player = new bf2_player($_GET['nick']); if($bf2_player->is_valid_player) { $nick = $bf2_player->stats['nick']; $gs = number_format($bf2_player->stats['scor']); $diff = get_time_difference("1 January 1970 00:00", date("d M Y G:i", $bf2_player->stats['time'])); $time = $diff['days']." days ".$diff['hours']." hours"; $lb = date('d M Y G:i', $bf2_player->stats['lbtl']); $kdr = round(($bf2_player->stats['kill'] / $bf2_player->stats['deth']), 2)." (".number_format($bf2_player->stats['kill'])."/".number_format($bf2_player->stats['deth']).")"; $sig = imagecreatefrompng('images/expanded_info.png'); imagealphablending($sig, true); $nickp = new point(66, 27); $gsp = new point(145, 56); $kdp = new point(181, 85); $tpp = new point(142, 113); $lbp = new point(196, 142); $font = "fonts/timesbd.ttf"; $txt_color = imagecolorallocate($sig, 255, 255, 255); // draw nick imagettftext($sig, 18, 0, $nickp->x, $nickp->y, $txt_color, $font, $nick); // draw global score imagettftext($sig, 18, 0, $gsp->x, $gsp->y, $txt_color, $font, $gs); // draw kill / death ratio imagettftext($sig, 18, 0, $kdp->x, $kdp->y, $txt_color, $font, $kdr); // draw time played imagettftext($sig, 18, 0, $tpp->x, $tpp->y, $txt_color, $font, $time); // draw last battle info imagettftext($sig, 18, 0, $lbp->x, $lbp->y, $txt_color, $font, $lb); header("Content-type: image/png"); imagepng($sig); imagedestroy($sig); } } /** * Function to calculate date or time difference. * * Function to calculate date or time difference. Returns an array or * false on error. * * @author J de Silva <giddomains@gmail.com> * @copyright Copyright © 2005, J de Silva * @link http://www.gidnetwork.com/b-16.html Get the date / time difference with PHP * @param string $start * @param string $end * @return array */ function get_time_difference( $start, $end ) { $uts['start'] = strtotime( $start ); $uts['end'] = strtotime( $end ); if( $uts['start']!==-1 && $uts['end']!==-1 ) { if( $uts['end'] >= $uts['start'] ) { $diff = $uts['end'] - $uts['start']; if( $days=intval((floor($diff/86400))) ) $diff = $diff % 86400; if( $hours=intval((floor($diff/3600))) ) $diff = $diff % 3600; if( $minutes=intval((floor($diff/60))) ) $diff = $diff % 60; $diff = intval( $diff ); return( array('days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) ); } else { trigger_error( "Ending date/time is earlier than the start date/time", E_USER_WARNING ); } } else { trigger_error( "Invalid date/time data detected", E_USER_WARNING ); } return( false ); } class point { var $x; var $y; function point($x, $y) { $this->x = $x; $this->y = $y; } } ?>
create a new folder named fonts and upload C:\windows\fonts\timesbd.ttf font to that (font) directory (times new font is owned by microsoft and I believe distribution of that font is illegal, so if you own a copy of windows you're free to use it, but cannot give it otherwise, so...).
then you get the image the same way as the avatar:
yoursite.com/prank/image.php?nick==[bc]=butcher
since you wrote the "Nick:" parts I didnt write that out (which will only matter if you switch background images). If you want that written out w/ the score info, then I'll need a blank image again (like the first one you posted).
Offline
#14 22 Aug 2006 5:11 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Hmmm, made a font folder inside /prank, put the timesbd.ttf in there and copied all the php into a file I called image.php, and uploaded that into /prank as well. But I get code that looks like something my printer would print on a bad day.
http://www.bamboocommandos.com/prank/image.php?nick==[BC]=Butcher
Offline
#16 22 Aug 2006 7:54 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
, I actually did at first, but it was with a capital f. You are still the greatest web developer I met
Offline
#18 09 Dec 2006 1:24 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Ok, I added the stuff in the first box to .htaccess, so it looks like this:
Code:
RewriteRule ^/bf2/(\w+)$\.html/ /bf2/index.php?op=foo&nick=$1 RewriteEngine On RewriteRule ^avatar/nick/([^/]*)/score\.jpg$ /bf2rank/index.php?nick=$1&score [L] RewriteRule ^avatar/nick/([^/]*)/score_delta\.jpg$ /bf2rank/?nick=$1&score&delta [L] RewriteRule ^avatar/nick/([^/]*)/delta_score\.jpg$ /bf2rank/?nick=$1&score&delta [L] RewriteRule ^avatar/nick/([^/]*)/score_notext\.jpg$ /bf2rank/?nick=$1&score&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_score\.jpg$ /bf2rank/?nick=$1&score&no_text [L] RewriteRule ^avatar/nick/([^/]*)/score_delta_notext\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/delta_score_notext\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_score_delta\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_delta_score\.jpg$ /bf2rank/?nick=$1&score&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/delta\.jpg$ /bf2rank/index.php?nick=$1&delta [L] RewriteRule ^avatar/nick/([^/]*)/notext\.jpg$ /bf2rank/?nick=$1&no_text [L] RewriteRule ^avatar/nick/([^/]*)/delta_notext\.jpg$ /bf2rank/?nick=$1&delta&no_text [L] RewriteRule ^avatar/nick/([^/]*)/notext_delta\.jpg$ /bf2rank/?nick=$1&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/score\.jpg$ /bf2rank/index.php?pid=$1&score [L] RewriteRule ^avatar/pid/([^/]*)/score_delta\.jpg$ /bf2rank/?pid=$1&score&delta [L] RewriteRule ^avatar/pid/([^/]*)/delta_score\.jpg$ /bf2rank/?pid=$1&score&delta [L] RewriteRule ^avatar/pid/([^/]*)/score_notext\.jpg$ /bf2rank/?pid=$1&score&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_score\.jpg$ /bf2rank/?pid=$1&score&no_text [L] RewriteRule ^avatar/pid/([^/]*)/score_delta_notext\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/delta_score_notext\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_score_delta\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_delta_score\.jpg$ /bf2rank/?pid=$1&score&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/delta\.jpg$ /bf2rank/index.php?pid=$1&delta [L] RewriteRule ^avatar/pid/([^/]*)/notext\.jpg$ /bf2rank/?pid=$1&no_text [L] RewriteRule ^avatar/pid/([^/]*)/delta_notext\.jpg$ /bf2rank/?pid=$1&delta&no_text [L] RewriteRule ^avatar/pid/([^/]*)/notext_delta\.jpg$ /bf2rank/?pid=$1&delta&no_text [L]
Wasnt sure if I were supposed to keep the top line, that was there from the start. Should I?
Offline
#20 09 Dec 2006 9:00 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Hmm, moved the top line to the bottom, but how do I know if this thingy applies to the prank "system"? This still works:
Code:
http://www.bamboocommandos.net/prank/image.php?nick==[BC]=Butcher
, but
Code:
http://www.bamboocommandos.net/prank/image.php?nick==[BC]=Butcher.jpg
still doesnt. Thinking that since the files for the picture and info are spread so widely inside the folder, maybe this rewrite doesnt target the right place...
Offline
#21 09 Dec 2006 4:34 pm
Re: Battlefield2 avatar
you may want to think about using pid's instead of nicks, just because url's dont like the = or the [] characters, and most forum image parsers will break on those characters.
the rewrite rules you copied are for the avatar, and wont work for you, so you can remove them and replace it w/ this:
Code:
RewriteRule ^prank/([^/]*)\.jpg$ /prank/index.php?nick=$1 [L]
and you'd link the image in like:
Code:
http://bamboocommandos.net/prank/%3D%5BBC%5D%3DButcher.jpg
note the URL encoding. url's use the '=' character for name value parameters, and the [] characters arent allowed, so you'll need to encode your name like that.
Offline
#22 09 Dec 2006 5:48 pm
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
Ok, removed everything in .htaccess and added the line you gave. But it seems I aint allowed to use pid's, for example:
Works
Code:
http://www.bamboocommandos.net/prank/image.php?nick==[BC]=Butcher
Doesnt work (as you mentioned, the parse error thingy)
Code:
http://www.bamboocommandos.net/prank/image.php?nick==[BC]=Butcher.jpg
Doesnt work (wont use pid)
Code:
http://www.bamboocommandos.net/prank/image.php?nick=43344896
I was sure it accepted pid's... Hmmm
Offline
#23 09 Dec 2006 6:55 pm
Re: Battlefield2 avatar
yea you're using the version of my bf2 stats class that only uses nicks (& doesnt allow pids).
you can add a few more rewrite rules so that folks can either leave off the =[BC]= or change it to something like bc_Butcher and the rewrite rules will change it to the correct thing
#1: bamboocommandos.net/prank/bc_butcher.jpg
Code:
RewriteRule ^prank/bc_(.*)\.jpg$ /prank/index.php?nick==[BC]=$1 [L]
#2: (leave off bc & just use nick minus the clan tag)
Code:
RewriteRule ^prank/([^/].*)\.jpg$ /prank/index.php?nick==[BC]=$1 [L]
so your url would look like:
#1:
Code:
http://bamboocommandos.net/prank/bc_butcher.jpg
#2:
Code:
http://bamboocommandos.net/prank/butcher.jpg
Offline
#24 10 Dec 2006 3:38 am
- Butcher
- Moderator
- From: Norway
- Registered: Jul 2006
- Posts: 308
Re: Battlefield2 avatar
I am required to have =[BC]=. because a lot of other folks are named Butcher...
And there is something going on with that image.php, if I write the example in the code, it gives me a 404.
I used example code #1 to test this
Will give me stats
Code:
http://www.bamboocommandos.net/prank/image.php?nick=bc_butcher
Wont give me stats
Code:
http://www.bamboocommandos.net/prank/image.php?nick=bc_butcher http://www.bamboocommandos.net/prank/bc_butcher
There is something weird here, it is obviously bound to use the image.php and then query out a response, but the rewrite somehow denies me of using bc_butcher, and .jpg didnt work anywhere...
Last edited by Butcher (10 Dec 2006 3:42 am)
Offline
#25 11 Dec 2006 7:38 am
Re: Battlefield2 avatar
ooooh, sorry m8.
#1
Code:
RewriteRule ^prank/bc_(.*)\.jpg$ /prank/image.php?nick==[BC]=$1 [L]
#2
Code:
RewriteRule ^prank/([^/].*)\.jpg$ /prank/image.php?nick=$1 [L]
#3
Code:
RewriteRule ^prank/([^/].*)\.jpg$ /prank/index.php?nick==[BC]=$1 [L]
the old rewrite rules re-wrote to index.php not image.php, so give this one a try (#3 will require you to convert = and []'s to url encoded values).
Offline