May 2, 2009

Runescape signature

How to make own runescape signature? This tutorial will answer your questions about making runescape signature in PHP using PHP-GD library, in eight steps.

What you need: you need webserver with PHP-GD library, file_get_contents() function on.

1st - defining headers:
$img=imagecreatefrompng("images/blue_sig.PNG");
header('Content-type: image/png');
Clear signatures:





-theese two images are clear signatures. All data from hiscores will be saved into one of theese two images. Btw. You can make your own clear signature, but it must be same form as theese.Save signatures into directory images/!

2nd -
getting data from hiscores:
$player=$_GET["player"];
$hiscore=file("http://hiscore.runescape.com/index_lite.ws?player=$player");
With this function you get informations from hiscores.runescape.com.
So you need function file_get_contents() on! If you are not 2mil in hiscore it show -1 level.

3rd - writing data into PNG image:
-imagestring(sourceimage, text width, posX, posy, "text string", text format);

-$attack=explode(",",$hiscore[1]);
with explode we can separate all data from line 1. Because all data in hiscores are writed in this form: xp,level,rank, and we are saving data into: $attack[0],$attack[1],$attack[2].
//attack
$attack=explode(",",$hiscore[1]);
imagestring($img, 2, 41, 9, "$attack[1]",$text);
//ranged
$ranged=explode(",",$hiscore[5]);
imagestring($img, 2, 41, 28, "$ranged[1]",$text);
//fletching
$fletching=explode(",",$hiscore[10]);
imagestring($img, 2, 41, 47, "$fletching[1]",$text);
//woodcutting
$woodcutting=explode(",",$hiscore[9]);
imagestring($img, 2, 41, 66, "$woodcutting[1]",$text);
//farming
$farming=explode(",",$hiscore[20]);
imagestring($img, 2, 41, 85, "$farming[1]",$text);

//strength
$strength=explode(",",$hiscore[3]);
imagestring($img, 2, 95, 9, "$strength[1]",$text);
//prayer
$prayer=explode(",",$hiscore[6]);
imagestring($img, 2, 95, 28, "$prayer[1]",$text);
//slayer
$slayer=explode(",",$hiscore[19]);
imagestring($img, 2, 95, 47, "$slayer[1]",$text);
//firmaking
$firemaking=explode(",",$hiscore[12]);
imagestring($img, 2, 95, 66, "$firemaking[1]",$text);
//herblore
$herblore=explode(",",$hiscore[16]);
imagestring($img, 2, 95, 85, "$herblore[1]",$text);

//defence
$defence=explode(",",$hiscore[2]);
imagestring($img, 2, 150, 9, "$defence[1]",$text);
//sumonning
$sumonning=explode(",",$hiscore[23]);
imagestring($img, 2, 150, 28, "$sumonning[1]",$text);
//agility
$agility=explode(",",$hiscore[17]);
imagestring($img, 2, 150, 47, "$agility[1]",$text);
//hunter
$hunter=explode(",",$hiscore[22]);
imagestring($img, 2, 150, 66, "$hunter[1]",$text);
//thieving
$thieving=explode(",",$hiscore[18]);
imagestring($img, 2, 150, 85, "$thieving[1]",$text);

//hitpoints
$hitpoints=explode(",",$hiscore[4]);
imagestring($img, 2, 207, 9, "$hitpoints[1]",$text);
//cooking
$cooking=explode(",",$hiscore[8]);
imagestring($img, 2, 207, 28, "$cooking[1]",$text);
//fishing
$fishing=explode(",",$hiscore[11]);
imagestring($img, 2, 207, 47, "$fishing[1]",$text);
//smithing
$smithing=explode(",",$hiscore[14]);
imagestring($img, 2, 207, 66, "$smithing[1]",$text);
//mining
$mining=explode(",",$hiscore[15]);
imagestring($img, 2, 207, 85, "$mining[1]",$text);

//magic
$magic=explode(",",$hiscore[7]);
imagestring($img, 2, 260, 9, "$magic[1]",$text);
//runecrafting
$runecrafting=explode(",",$hiscore[21]);
imagestring($img, 2, 260, 28, "$runecrafting[1]",$text);
//crafting
$crafting=explode(",",$hiscore[13]);
imagestring($img, 2, 260, 47, "$crafting[1]",$text);
//construction
$construction=explode(",",$hiscore[22]);
imagestring($img, 2, 260, 66, "$construction[1]",$text);

4th - calculating and writing combat level
This is official formula for calculating combat level.

$attack=explode(",",$hiscore[1]);
$defence=explode(",",$hiscore[2]);
$strength=explode(",",$hiscore[3]);
$hitpoints=explode(",",$hiscore[4]);
$ranged=explode(",",$hiscore[5]);
$prayer=explode(",",$hiscore[6]);
$magic=explode(",",$hiscore[7]);
$cmbt_lvl=1/4*(13/10*($attack[1]+$strength[1])+$defence[1]+$hitpoints[1]+1/2*$prayer[1]);
$combat=round($cmbt_lvl, 0);
imagestring($img, 2, 260, 85, "$combat",$text);

5th - name,total lvl, total xp
//name
imagestring($img, 2, 25, 110, "$player",$text);
//total level
$total=explode(",",$hiscore[0]);
imagestring($img, 2, 145, 105, "$total[1]",$text);
//total xp
$total=explode(",",$hiscore[0]);
$xp=number_format($total[2]);
imagestring($img, 2, 190, 105, "$xp",$text);

6th - writing name of your portal and ending headers
imagestring($img, 2, 170, 120, "milanpk.blogspot.com",$text);

-you can write your own name of your portal, so please add this page as source.

imagepng($img);
imagedestroy($img);

Save file into same directory as images!!! and name it image.php!

7th- Including image into website/forum etc.

<img src="image.php?player=milanpk" border="0">

this html code will input image into your website. you can make system, where players can save images on your server and only adding html code on theirs sites or forums or etc... Im sorry, My English is very Bad.

If script dont work, or you need help with other script please contact me (milan.pk@hotmail.com).

8th - The Final Result



Tip!: Install Xampp- webserver and test this script on localhost...






1 comment: