• 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

Mango u want to go war with feloth? man don't kill yourself, many people still loving you.

btw, i like more the old one =(
 
Mango u want to go war with feloth? man don't kill yourself, many people still loving you.

btw, i like more the old one =(
this guy crazy or what?:ninja:
 
Mango u want to go war with feloth? man don't kill yourself, many people still loving you.

btw, i like more the old one =(
It is still possible to use the old background, this background was made quickly just to show the possibility to use equipments.

About the war, me and Alex (Feloth) are friends and were just joking around - there's no need to worry. :$
 
would it be possible to include this into a php script such as:
Code:
file.php
Code:
#class MadGDText
#{

after those lines something along the lines of
<?php include=('file.txt')/>

turn it into a function of

$image->addTextOverlay('file.txt')->setPosition(xxx, xxx);;

basically add a include of a html/php/txt file over the image,
so you can have it display dynamically --

example ->

http://www..com/images/imagetext.php

and have it sized and included in the image ->

http://www..com/images/image.png
 
Of course (edit: you are still able to set a second argument to provide your text with a style).
PHP:
$image->addText(file_get_contents('file.txt'))->setPosition(10, 10);
 
this works under the same parameters as php code correct? not just able to read txt files?...

<3 and its cool you can still add the styles along with it :D

Where would you set these, at the end, under public? -- im using this as my next signature,
along with a lil something something for a script (hope it works)
 
Note that, if you include a php file, it will only grab the text that you have printed out. Not the actual code.
PHP:
$styled = array(
    'font' => 'arial.ttf',
    'size' => 8,
    'color' => '#AAFFFF',
    'shadow' => false
);

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

$image->addText(file_get_contents('text.php'), $styled)->setPosition(10, 10);

$image->display();
 
Based off the script, the "addText" seems to be bugging, whether or not i do a simple sentance like "$image->addText('hello')->setPosition(10, 10);" or the file_contents function or whatnot, it simple gives me this, "The image “http://jacobs-1337.sytes.net/signature/signature.php” cannot be displayed, because it contains errors."
 
This is what i got -- and its erroring~
Code:
<?PHP
 
	// Define GD fonts.
	define('MADGD_FIRSTFONT', 1);
	define('MADGD_SECONDFONT', 2);
	define('MADGD_THIRDFONT', 3);
	define('MADGD_FOURTHFONT', 4);
	define('MADGD_FIFTHFONT', 5);
	define('MADGD_STACK', 'stackIt');
 
	// Predefined positions.
	define('AMULET_X', 340);
	define('AMULET_Y', 18);
	define('HELMET_X', 377);
	define('HELMET_Y', 4);
	define('BACKPACK_X', 415);
	define('BACKPACK_Y', 18);
	define('LEFTHAND_X', 340);
	define('LEFTHAND_Y', 55);
	define('ARMOR_X', 377);
	define('ARMOR_Y', 41);
	define('RIGHTHAND_X', 414);
	define('RIGHTHAND_Y', 55);
	define('RING_X', 340);
	define('RING_Y', 92);
	define('LEGS_X', 377);
	define('LEGS_Y', 78);
	define('AMMO_X', 414);
	define('AMMO_Y', 92);
	define('BOOTS_X', 377);
	define('BOOTS_Y', 115);
 
	$GDPreviousPositions = array('x' => 0, 'y' => 0, 'l' => 0);
 
	// Create a class to handle icons.
	class MadGDIcon
	{
		// Define private variables.
		private $object, $icon;
 
		// Create the constructor.
		public function __construct($object, $icon)
		{
			// Set the private variable values.
			$this->object = $object;
			$this->icon = $icon;
		}
 
		// Create a public function to set the positions.
		public function setPosition($x, $y = false)
		{
			// Check if the icon exists.
			if(file_exists($this->icon))
			{
				global $GDPreviousPositions;
				// Check if x is set to GDCONFIG_STACK.
				if($x == MADGD_STACK)
				{
					$this->position['x'] = $GDPreviousPositions['x'] + $GDPreviousPositions['l'] + ($y == false ? 5 : $y);
					$this->position['y'] = $GDPreviousPositions['y'];
				}
				else
				{
					$this->position['x'] = $x;
					$this->position['y'] = $y;
				}
 
				// Get icon size.
				$size = getimagesize($this->icon);
 
				$GDPreviousPositions['x'] = $this->position['x'];
				$GDPreviousPositions['y'] = $this->position['y'];
				$GDPreviousPositions['l'] = $size[0];
 
				// Check for the file extension.
				$object = pathinfo($this->icon);
 
				// Run several checks of the extension until a match is found.
				switch(strtolower($object['extension']))
				{
					case 'png':
						// Set the GD type to PNG.
						$return = imagecreatefrompng($this->icon);
					break;
					case 'gif':
						// Set the GD type to GIF.
						$return = imagecreatefromgif($this->icon);
					break;
					default:
						// Set the GD type to JPG.
						$return = imagecreatefromjpeg($this->icon);
					break;
				}
 
				return imagecopy($this->object, $return, $this->position['x'], $this->position['y'], 0, 0, $size[0], $size[1]);
			}
			else
			{
				imagestring($this->object, 'fonts/arial.ttf', $this->position['x']+1, $this->position['y']+1, 'Icon: not found', imagecolorallocate($this->object, 0, 0, 0));
				imagestring($this->object, 'fonts/arial.ttf', $this->position['x'], $this->position['y'], 'Icon: not found', imagecolorallocate($this->object, 230, 0, 0));
			}
		}
	}
 
	// Create a class to handle text strings.
	class MadGDText
	{
		// Define private variables.
		private $object, $text, $font, $color, $size, $position = array('x', 'y'), $shadow;
 
		// Create the constructor.
		public function __construct($object, $text, $color, $font, $shadow)
		{
			// Check if the color is false.
			if($color == false)
			{
				$color = array(255, 255, 255);
			}
 
			// Set the private variable values.
			$this->object = $object;
			$this->text = $text;
			$this->font = $font[0];
			$this->color = $color;
			$this->size = (isset($font[1]) ? $font[1] : 10 );
			$this->shadow = $shadow;
		}
 
		// Create a public function to set the positions.
		public function setPosition($x, $y = false)
		{
			global $GDPreviousPositions;
			// Check if x is set to GDCONFIG_STACK.
			if($x == MADGD_STACK)
			{
				$this->position['x'] = $GDPreviousPositions['x'] + $GDPreviousPositions['l'] + ($y == false ? 5 : $y);
				$this->position['y'] = $GDPreviousPositions['y'];
			}
			else
			{
				$this->position['x'] = $x;
				$this->position['y'] = $y;
			}
 
			$textsize = (is_int($this->font) ? null : imagettfbbox($this->size, 0, $this->font, $this->text));
			$GDPreviousPositions['x'] = $this->position['x'];
			$GDPreviousPositions['y'] = $this->position['y'];
			$GDPreviousPositions['l'] = (is_int($this->font) ? imagefontwidth($this->font) * strlen($this->text) : $textsize[2]);
 
			// Return the text string.
			if(is_int($this->font))
			{
				if($this->shadow)
				{
					imagestring($this->object, $this->font, $this->position['x']+1, $this->position['y']+1, $this->text, imagecolorallocate($this->object, 0, 0, 0));
				}
				imagestring($this->object, $this->font, $this->position['x'], $this->position['y'], $this->text, imagecolorallocate($this->object, $this->color[0], $this->color[1], $this->color[2]));
			}
			else
			{
				if($this->shadow)
				{
					imagettftext($this->object, $this->size, 0, $this->position['x']+1, $this->position['y']+11, imagecolorallocate($this->object, 0, 0, 0), $this->font, $this->text);
				}
				imagettftext($this->object, $this->size, 0, $this->position['x'], $this->position['y']+10, imagecolorallocate($this->object, $this->color[0], $this->color[1], $this->color[2]), $this->font, $this->text);
			}
		}
	}
 
	// Create a class to handle GD images.
	class MadGD
	{
		// Define private variables.
		protected $background, $object;
		// Define public variables.
		public $testMode = false;
 
		// Create a public function to set the background image.
		public function setBackground($background)
		{
			// Set the private variable values.
			$this->background = $background;
			// Check for the file extension.
			$object = pathinfo($this->background);
 
			// Run several checks of the extension until a match is found.
			switch(strtolower($object['extension']))
			{
				case 'png':
					// Set the GD type to PNG.
					if(!$this->testMode) header('Content-Type: image/png');
					$this->object = imagecreatefrompng($this->background);
				break;
				case 'gif':
					// Set the GD type to GIF.
					if(!$this->testMode) header('Content-Type: image/gif');
					$this->object = imagecreatefromgif($this->background);
				break;
				default:
					// Set the GD type to JPG.
					if(!$this->testMode) header('Content-Type: image/jpeg');
					$this->object = imagecreatefromjpeg($this->background);
				break;
			}
			// Return the GD object.
			return $this->object;
		}
 
		// Create a public function to add icons.
		public function addIcon($icon)
		{
			return new MadGDIcon($this->object, $icon);
		}
 
		// Create a public function to add text strings.
		public function addText($text, $config = array())
		{
			// Set the default configuration.
			$defaultConfig = array('font' => MADGD_SECONDFONT, 'size' => 9, 'color' => '#FFFFFF', 'shadow' => true);
			// Check if all of the keys exists in the new config.
			foreach($defaultConfig as $defaultKey => $defaultValue)
			{
				if(!array_key_exists($defaultKey, $config))
				{
					$config[$defaultKey] = $defaultValue;
				}
			}
 
			// Return a new GDTextString object.
			return new MadGDText($this->object, $text, $this->HexToRGB($config['color']), array($config['font'], $config['size']), $config['shadow']);
		}
 
		// Create a private function to transform any HEX values into RGB format.
		private function HexToRGB($hex)
		{
			// Check if it is HEX.
			if(!is_array($hex))
			{
				// Remove any # character.
				$hex = ereg_replace("#", "", $hex);
				$color = array();
				// Check whether it is 6 characters long.
				if(strlen($hex) == 6)
				{
					// Set the new values.
					$color[0] = hexdec(substr($hex, 0, 2));
					$color[1] = hexdec(substr($hex, 2, 2));
					$color[2] = hexdec(substr($hex, 4, 2));
				}
			}
			// Return the color.
			return (!is_array($hex) ? $color : $hex);
		}
 
		// Create a public function to display the image as PNG and unset/destroy it after it is completed.
		public function display()
		{
			imagepng($this->object);
			imagedestroy($this->object);
		}
		public function unnn()
		{
			unset($this);
		}
	}
$image = new MadGD;
$image->addText('hello world')->setPosition(10, 10);
$image->setBackground('Signature.png');
$image->display();
$image->unnn();

I thought the unset function was messing it up~ but i realised the argument was called after..
So the extra unnn function doesn't compromise anything, it just breaks it down a bit..
 
You set the text before even setting the background. That is most likely what is causing the issue, seeing as you cannot write on blank space. However, if you would like to see any error messages you can do $image->testMode = true; (with a large M at testMode) after the 'new MadGD' line.
 
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 (DaoPay API © Absolute Mango)). 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! :<

I got same addicts.
 
Coz most of the web hosting services uses it.
so why you don't use your brain while most of people uses it?


Mango, really nice class. I will use it in my small project.
 
so why you don't use your brain while most of people uses it?


Mango, really nice class. I will use it in my small project.

Don't attempt to type in english to put someone down,
if you can't write proper english... --

Im sure everyone can use google translator if you were to write
in poland,
Next time try not to be so arrogant. Signed -C00KIE [no harm intended]
 
Don't attempt to type in english to put someone down,
if you can't write proper english... --

Im sure everyone can use google translator if you were to write
in poland,
Next time try not to be so arrogant. Signed -C00KIE [no harm intended]

Well I didn't get him either.
 
Back
Top