• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Character Signature API

Chris

Inactive
Senator
Joined
Aug 11, 2008
Messages
2,628
Solutions
2
Reaction score
240
Some of you may be aware that not that long ago I released a character signature script, and some of you may even be using it. I would like you to stop using it, immediately. I have a new version for you, and even if we put that aside, it was poorly done.

Download:
GD API © Absolute Mango

Method List (only those with public access):

  • $image->setBackground(image);
  • $image->addText(text, configArray)->setPosition(x, y);
  • $image->addIcon(image)->setPosition(x, y);
  • $image->display();

Example #1:
What you need to do before you do anything else, is to actually create a background for it and then load/display it.
PHP:
$image = new MadGD;
$image->setBackground('mySignature.png');
$image->display();
example1.png



Example #2:
Now let's imagine you would want to add a piece of text on the image. With this API it is as easy as never before!
PHP:
$image = new MadGD;
$image->setBackground('mySignature.png');

$image->addText('This is my awesome sentance!')->setPosition(10, 10);;

$image->display();
example2.png



Example #3:
Now let's imagine you would like this to be dynamic. Then you would have no clue whatsoever how long a string may be (e.g. character name) and you would want the next string to come right after the previous text without having to set a static position.
PHP:
$image = new MadGD;
$image->setBackground('mySignature.png');

$image->addText('Name:')->setPosition(10, 10);
$image->addText('Absolute Mango')->setPosition(MADGD_STACK);

$image->display();
As you can see, there's an option to set the position to MADGD_STACK which means that it will put it next to the previous entry (with a 5pixel margin, you can change that also by adding a second argument "->setPosition(MADGD_STACK, -5)").
example3.png



Example #4:
There is also the option to style your text strings accordingly (not all of the 4 key elements are required, only the ones you wish for).
PHP:
$styled = array(
    'font' => 'arial.ttf',
    'size' => 8,
    'color' => '#AAFFFF',
    'shadow' => false
);

$image = new MadGD;
$image->setBackground('mySignature.png');

$image->addText('Name:')->setPosition(10, 10);
$image->addText('Absolute Mango', $styled)->setPosition(MADGD_STACK);

$image->display();
example4.png
'


Example #5:
Then we have the option to add icons to our image (e.g. a characters equipments). It works exactly the same way as the addText function does, only that you are not able to style it with a second command. However, you are able to use the MADGD_STACK functionality.
PHP:
$styled = array(
    'font' => 'arial.ttf',
    'size' => 8,
    'color' => '#AAFFFF',
    'shadow' => false
);

$image = new MadGD;
$image->setBackground('mySignature.png');

$image->addText('Name:')->setPosition(10, 10);
$image->addText('Absolute Mango', $styled)->setPosition(MADGD_STACK);

$image->addIcon('2400.gif')->setPosition(LEFTHAND_X, LEFTHAND_Y);

$image->display();
example5.png




There are several predefined variables such as the LEFTHAND_X and the LEFTHAND_Y ones, but it is not required to use those. If you do however use the same background as I do, the predefined equipment variables are positioned correctly and highly recommended to use.

That's about it folks!
If you have any questions at all, please do not hesitate to ask.
 
Last edited:
I might add that a finished product may look something like this:
index.php
 
What about saving method Chris :(? I don't want my apache crashed if there will be too many requests so I will CRON it.
 
Just add a second argument to imagepng function.
PHP:
imagepng($this->object, 'mynewfile.png');
 
epic release! It's even better than last one
cool, rep+
 
Last edited:
You used my name without permission. But I forgive you <333 :D

Great work!! :D:$
 
What are you referring to exactly?
 
Youre using { & } on a new row :C

Ps. It's nothing wrong, but it's a "thing" i have. Call it a sickness or w/e haha, but I can't stand { on a new row.
It's like typing <img src=heeheh.jpg> for my eyes. ahahah. (incase no one understood that example, it's in my eyes "correct" to write <img src="eheheh.jpg" alt="" />.

But I truly see you know your way around object-based programming. :D
 
Last edited:
Oh, heh. It's just a matter of taste, and there won't be any noticeable impact on the human eye due to the small size of the script.

Edit: Just noticed your edition. I understand your point of view, I myself have like months of { on new lines, and then suddenly I feel that it looks better when it is on the same row (just look at my daopay api (http://api.madphp.org/daopay/)). I cannot just stick with one (obviously I stick with one way in the same project).

And I totally agree with you, when it comes to that HTML part. I can not use double quotes in PHP, I highly dislike it. I also dislike using single quotes when it comes to HTML.

We're so complex mate! :<
 
Last edited:
Back
Top