Jump to content

? servers

? players online

Need help creating a Dynamic Signature Generator

Recommended Posts


  • Content Count:  326
  • Joined:  12/15/08
  • Status:  Offline

Essentially I want to make one of those forum signature generators.

All the information needed will be derived from this API:

 

http://api.fomportal.com/20101108/character.php?name=$ign

 

I know I need to use a GET command (in HTTP syntax) to gather the information from the API.

 

The response from the API is in XML, an example is shown below:

 

ok

Test

Test Player/player_name>

Male

FactionName

3

Leader Department

 

 

So essentially all of the response categories (player name, gender, faction etc.) will be the text displayed on the sig. I know BASIC PHP so I really have no clue how to approach this. I want this code to be applicable to a website, so essentially a user can put in their ingame name and the code will gather the information, translate some information into images (like a faction or rank image) and display the rest of the information as text in the signature. The result will be a complete signature for the user to save. Any help would be appreciated.

Edited by WackyIraqi
Link to comment

  • Content Count:  2085
  • Joined:  04/19/10
  • Status:  Offline

First you'd probably want to get the basic dynamic image creation done. Simple steps first.

 

Here is an example of a random-quotes script (left a ton of comments in, hopefully they will help):

// Path to our font file
$font = '/path/to/fonts/arial.ttf';
$fontsize = 12;

// array of random quotes
$quotes = array(
"hurr",
"durr",
"gurr");

// generate a random number with range of # of array elements
$pos = rand(0,count($quotes)-1);
// get the quote and word wrap it
$quote = wordwrap($quotes[$pos],50);

header("Content-type: image/png"); //Picture Format
header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // NO CACHE

/*image generation code*/
//create Image of size 350px x 75px
$dims = imagettfbbox($fontsize, 0, $font, $quote);

$width = $dims[4] - $dims[6]; // upper-right x minus upper-left x 
$height = $dims[3] - $dims[5]; // lower-right y minus upper-right y

$bg = imagecreatetruecolor($width, $height);

//This will make it transparent
imagesavealpha($bg, true);

$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);

//Text to be written

// White text
$white = imagecolorallocate($bg, 255, 255, 255);
// Grey Text
$grey = imagecolorallocate($bg, 128, 128, 128);
// Black Text
$black = imagecolorallocate($bg, 0,0,0);

//Writes text to the image using fonts using FreeType 2
imagettftext($bg, $fontsize, 0, 0, 12, $grey, $font, $quote);

//Create image
imagepng($bg);

//destroy image
ImageDestroy($bg);

?>

Preview (using different stupid quotes).

 

That should help a lot. You now just need to find a simple method of parsing the XML data. Most of the major work (image creation) is pretty much exampled above.

 

Good luck, hope I helped a bit.

Link to comment

  • Content Count:  326
  • Joined:  12/15/08
  • Status:  Offline

First you'd probably want to get the basic dynamic image creation done. Simple steps first.

 

Here is an example of a random-quotes script (left a ton of comments in, hopefully they will help):

// Path to our font file
$font = '/path/to/fonts/arial.ttf';
$fontsize = 12;

// array of random quotes
$quotes = array(
"hurr",
"durr",
"gurr");

// generate a random number with range of # of array elements
$pos = rand(0,count($quotes)-1);
// get the quote and word wrap it
$quote = wordwrap($quotes[$pos],50);

header("Content-type: image/png"); //Picture Format
header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // NO CACHE

/*image generation code*/
//create Image of size 350px x 75px
$dims = imagettfbbox($fontsize, 0, $font, $quote);

$width = $dims[4] - $dims[6]; // upper-right x minus upper-left x 
$height = $dims[3] - $dims[5]; // lower-right y minus upper-right y

$bg = imagecreatetruecolor($width, $height);

//This will make it transparent
imagesavealpha($bg, true);

$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);

//Text to be written

// White text
$white = imagecolorallocate($bg, 255, 255, 255);
// Grey Text
$grey = imagecolorallocate($bg, 128, 128, 128);
// Black Text
$black = imagecolorallocate($bg, 0,0,0);

//Writes text to the image using fonts using FreeType 2
imagettftext($bg, $fontsize, 0, 0, 12, $grey, $font, $quote);

//Create image
imagepng($bg);

//destroy image
ImageDestroy($bg);

?>

Preview (using different stupid quotes).

 

That should help a lot. You now just need to find a simple method of parsing the XML data. Most of the major work (image creation) is pretty much exampled above.

 

Good luck, hope I helped a bit.

 

Thanks a lot, really do appreciate your time and effort. I'll see what I can do from there.

Link to comment

Reply to Thread

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...