• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved [PHP&ModernAAC] Signature change img to htdoc/public/image/items

Status
Not open for further replies.

pasibun

New Member
Joined
Nov 7, 2011
Messages
147
Reaction score
1
Hey,

The signature script works excellent, for one flaw. When you use custom items it does not recognize them and they dont place an image.
Appearantly we have to change the .dat, .spr and the .otb.

Ive tried asking on the forum, I tried it my self but im still at point 0 on this issue.

So what if we change the approach. Cant I let the images be loaded via "htdoc/public/images/items/...?
I can just place every custom made item there. And I finaly have my signature script working properly!

Just I cant figure out the php part of the script

CreateItem.class.php:
PHP:
<?PHP

	// Set the item ID to re-create.
	$myid = ( isset( $myId ) ? $myId : 0 );
	$mycount = ( isset( $myCount ) ? $myCount : 0 );


	if ( $myid >= 100 )
	{
		$files = array(
			'otb' => INJECTIONPATH.'/system/items.otb',
			'spr' => INJECTIONPATH.'/system/Tibia.spr',
			'dat' => INJECTIONPATH.'/system/Tibia.dat'
		);
		$newImagePath = BASEPATH.'/public/images/items/'.( $mycount > 1 ? $myid.'/'.$mycount : $myid ).'.gif';

		
		
		
		
		
		if ( !defined( 'HEX_PREFIX' ) )
			define( 'HEX_PREFIX', '0x' );
		
		$nostand = false;

		/* READ OTB */
		$otb = fopen( $files['otb'], 'rb' );
		while( false !== ( $char = fgetc( $otb ) ) )
		{
			$byte = HEX_PREFIX.bin2hex( $char );

			if ( $byte == 0xFE )
				$init = true;
			elseif ( $byte == 0x10 and $init )
			{
				extract( unpack( 'x2/Ssid', fread( $otb, 4 ) ) );

				if ( $myid == $sid )
				{
					if ( HEX_PREFIX.bin2hex( fread( $otb, 1 ) ) == 0x11 )
					{
						extract( unpack( 'x2/Smyid', fread( $otb, 4 ) ) );
						break;
					}
				}
				$init = false;
			}
		}

		fclose( $otb );
		/* CLOSE OTB */

		/* READ DAT */
		$dat = fopen( $files['dat'], 'rb' );
		$max = array_sum( unpack( 'x4/S*', fread( $dat, 12 ) ) );

		if ( $myid > $max )
		{
			return false; #trigger_error( sprintf( 'Out of range', ftell( $dat ) ), E_USER_ERROR );
		}

		for( $i = 100; $i <= $myid; $i++ )
		{
			while( ( $byte = HEX_PREFIX.bin2hex( fgetc( $dat ) ) ) != 0xFF )
			{
				$offset = 0;
				switch( $byte )
				{
					case 0x00:
					case 0x09:
					case 0x0A:
					case 0x1A:
					case 0x1D:
					case 0x1E:
						$offset = 2;
						break;

					case 0x16:
					case 0x19:
						$offset = 4;
						break;

					case 0x01:
					case 0x02:
					case 0x03:
					case 0x04:
					case 0x05:
					case 0x06:
					case 0x07:
					case 0x08:
					case 0x0B:
					case 0x0C:
					case 0x0D:
					case 0x0E:
					case 0x0F:
					case 0x10:
					case 0x11:
					case 0x12:
					case 0x13:
					case 0x14:
					case 0x15:
					case 0x17:
					case 0x18:
					case 0x1B:
					case 0x1C:
					case 0x1F:
					case 0x20:
						break;

					default:
						return false; #trigger_error( sprintf( 'Unknown .DAT byte %s (previous byte: %s; address %x)', $byte, $prev, ftell( $dat ), E_USER_ERROR ) );
						break;
				}

				$prev = $byte;
				fseek( $dat, $offset, SEEK_CUR );
			}
			extract( unpack( 'Cwidth/Cheight', fread( $dat, 2 ) ) );

			if ( $width > 1 or $height > 1 )
			{
				fseek( $dat, 1, SEEK_CUR );
				$nostand = true;
			}

			$sprites_c = array_product( unpack( 'C*', fread( $dat, 5 ) ) ) * $width * $height;
			$sprites = unpack( 'S*', fread( $dat, 2 * $sprites_c ) );
		}

		fclose( $dat );
		/* CLOSE DAT */


		/* READ SPR */
		$spr = fopen( $files['spr'], 'rb' );

		/*
		if ( $nostand )
		{
			for( $i = 0; $i < sizeof( $sprites ) / 4; $i++ )
			{
				$sprites = array_merge( (array) $sprites, array_reverse( array_slice( $sprites, $i * 4, 4 ) ) );
			}
		}
		else
		{
			$sprites = (array) $sprites[array_rand( $sprites ) ];
		}
		*/

		if ( !function_exists( 'stackId' ) )
		{
			function stackId( $count )
			{
				if ( $count >= 50 )
					$stack = 8;
				elseif ( $count >= 25 )
					$stack = 7;
				elseif ( $count >= 10 )
					$stack = 6;
				elseif ( $count >= 5 )
					$stack = 5;
				elseif ( $count >= 4 )
					$stack = 4;
				elseif ( $count >= 3 )
					$stack = 3;
				elseif ( $count >= 2 )
					$stack = 2;
				else
					$stack = 1;
	
				return $stack;
			}
		}

		if ( array_key_exists( stackId( $mycount ), $sprites ) )
		{
			$sprites = (array) $sprites[stackId( $mycount )];
		}
		else
		{
			$sprites = (array) $sprites[array_rand( $sprites ) ];
		}

		fseek( $spr, 6 );

		$sprite = imagecreatetruecolor( ( 32 * $width < 32 ? 32 : 32 * $width ), ( 32 * $height < 32 ? 32 : 32 * $height ) );
		imagecolortransparent( $sprite, imagecolorallocate( $sprite, 0, 0, 0 ) );

		foreach( $sprites as $key => $value )
		{
			fseek( $spr, 6 + ( $value - 1 ) * 4 );
			extract( unpack( 'Laddress', fread( $spr, 4 ) ) );

			fseek( $spr, $address + 3 );
			extract( unpack( 'Ssize', fread( $spr, 2 ) ) );

			list( $num, $bit ) = array( 0, 0 );

			while( $bit < $size )
			{
				$pixels = unpack( 'Strans/Scolored', fread( $spr, 4 ) );
				$num += $pixels['trans'];
				for( $i = 0; $i < $pixels['colored']; $i++ )
				{
					extract( unpack( 'Cred/Cgreen/Cblue', fread( $spr, 3 ) ) );

					$red = ( $red == 0 ? ( $green == 0 ? ( $blue == 0 ? 1 : $red ) : $red ) : $red );

					imagesetpixel( $sprite, 
						$num % 32 + ( $key % 2 == 1 ? 32 : 0 ), 
						$num / 32 + ( $key % 4 != 1 and $key % 4 != 0 ? 32 : 0 ), 
						imagecolorallocate( $sprite, $red, $green, $blue ) );

					$num++;
				}

				$bit += 4 + 3 * $pixels['colored'];
			}
		}

		if ( $mycount >= 2 )
		{
			if ( $mycount > 100 )
				$mycount = 100;

			$font = 3;
			$length = imagefontwidth( $font ) * strlen( $mycount );

			$pos = array(
				'x' => ( 32 * $width ) - ( $length + 1 ),
				'y' => ( 32 * $height ) - 13
			);
			imagestring( $sprite, $font, $pos['x'] - 1, $pos['y'] - 1, $mycount, imagecolorallocate( $sprite, 1, 1, 1 ) );
			imagestring( $sprite, $font, $pos['x'], $pos['y'] - 1, $mycount, imagecolorallocate( $sprite, 1, 1, 1 ) );
			imagestring( $sprite, $font, $pos['x'] - 1, $pos['y'], $mycount, imagecolorallocate( $sprite, 1, 1, 1 ) );

			imagestring( $sprite, $font, $pos['x'], $pos['y'] + 1, $mycount, imagecolorallocate( $sprite, 1, 1, 1 ) );
			imagestring( $sprite, $font, $pos['x'] + 1, $pos['y'], $mycount, imagecolorallocate( $sprite, 1, 1, 1 ) );
			imagestring( $sprite, $font, $pos['x'] + 1, $pos['y'] + 1, $mycount, imagecolorallocate( $sprite, 1, 1, 1 ) );

			imagestring( $sprite, $font, $pos['x'], $pos['y'], $mycount, imagecolorallocate( $sprite, 219, 219, 219 ) );
		}

		fclose( $spr );
		/* CLOSE SPR */

		if ( $mycount > 1 )
		{
			$folder = explode( '/', $newImagePath );
			unset( $folder[count( $folder )-1] );
			$folder = implode( '/', $folder );
			if ( !file_exists( $folder ) )
			{
				mkdir( $folder );
			}
		}
		imagegif( $sprite, $newImagePath );
	}

ImageDraw.class.php:
PHP:
<?PHP

	ob_start( );
	
	class ImageDraw
	{
		protected $enabled;
		protected static $imageDraw;
		protected $storedObjects = array( );
		
		public $instance;
		public $cache, $cacheDirectory, $cacheExpire, $cacheFile;
		public $imageWidth, $imageHeight, $imageColour, $imageTransparency,
			 $imageBackground, $imageBorder, $imageStrings, $imageIcons,
			 $imageFont, $imageRows, $imageSpaces, $imageX, $imageY,
			 $imageW, $imageH;
	
	
		/**
		 * @param integer/boolean $enabled
		 * @access public
		 * @return null
		**/
		public function __construct( $enabled = 1, $cache = 1 )
		{
			// Enable or disable the entire draw queue.
			$this->enabled = (int) $enabled;
			// Enable or disable the cache.
			$this->cache = (int) $cache;
			
			// Add available objects to the storedObjects variable.
			$this->storedObjects = array(
				'ImageDraw_Image' => array(
					'backgrounds', 'background', 'bg', 'image', 'img', 'picture', 'pic', 'icon', 'graphic'
				),
				'ImageDraw_Cache' => array(
					'cache', 'save', 'store', 'file', 'storage'
				)
			);
			
			// Save the instance in to a class variable.
			self::$imageDraw =& $this;
		}
		
		
		/**
		 * Return the ImageDraw instance
		 * 
		 * @access public
		 * @static true
		 * @return instance
		**/
		public static function getInstance( )
		{
			if ( !isset( self::$imageDraw ) )
			{
				new self();
			}
			return self::$imageDraw;
		}
		
		
		/**
		 * Determine whether the draw queue is enabled or not
		 *
		 * @access public
		 * @return boolean
		**/
		public function isEnabled( )
		{
			if ( (int) $this->enabled == 0 )
			{
				return FALSE;
			}
			return TRUE;
		}
		
		
		/**
		 * Create an object
		 *
		 * @param string $object
		 * @access public
		 * @return instance
		**/
		public function createObject( $object )
		{
			foreach( $this->storedObjects as $instance => $keywords )
			{
				if ( !in_array( strtolower( $object ), $keywords ) )
				{
					continue;
				}
				$this->instance = new $instance( self::$imageDraw );
				break;
			}
			return $this->instance;
		}
		
		
		/**
		 * Render all of the class variables to build the outcome
		 *
		 * @param string $savePath
		 * @access public
		 * @return null
		**/
		public function build( $savePath = NULL )
		{
			// Render a background colour if there is one.
			if ( $this->imageColour )
			{
				list( $RED, $GREEN, $BLUE ) = $this->_convertColour( $this->imageColour );
				$this->instance = imagecreate( $this->imageWidth, $this->imageHeight );
				imagefill( $this->instance, 0, 0, imagecolorallocate( $this->instance, $RED, $GREEN, $BLUE ) );
			}
			
			// Render a transparent background if there is one.
			if ( $this->imageTransparency )
			{
				$this->instance = imagecreatetruecolor( $this->imageWidth, $this->imageHeight );
				imagealphablending( $this->instance, FALSE );
				imagesavealpha( $this->instance, TRUE );
				imagefill( $this->instance, 0, 0, imagecolorallocatealpha( $this->instance, 41, 41, 41, 127 ) );
				imagealphablending( $this->instance, TRUE );
			}
			
			// Render a background image if there is one.
			if ( $this->imageBackground )
			{
				switch( $this->imageExtension )
				{
					case 'png':
						$this->instance = imagecreatefrompng( $this->imageBackground );
						break;

					case 'gif':
						$this->instance = imagecreatefromgif( $this->imageBackground );
						break;

					case 'jpg':
					case 'jpeg':
						$this->instance = imagecreatefromjpeg( $this->imageBackground );
						break;
				}
			}
			
			// Render a border if there is one.
			if( isset( $this->imageBorder[0] ) && isset( $this->imageBorder[1] ) )
			{
				list( $x1, $y1, $x2, $y2 ) = array( 0, 0, imagesx( $this->instance ) - 1, imagesy( $this->instance ) - 1 );
				list( $RED, $GREEN, $BLUE ) = $this->_convertColour( $this->imageBorder[1] );
				for ( $i = 0; $i < $this->imageBorder[0]; $i++ )
				{
					imagerectangle( $this->instance, $x1++, $y1++, $x2--, $y2--, imagecolorallocate( $this->instance, $RED, $GREEN, $BLUE ) );
				}
			}
			
			// Render all of the strings.
			if ( !isset( $this->imageFont[0] ) )
			{
				$this->imageFont[0] = 2;
			}
			if ( is_array( $this->imageStrings ) )
			{
				foreach( $this->imageStrings as $key => $string )
				{
					// Decide whether to use the default font or the custom one.
					list( $font, $size, $colour ) = array( $this->imageFont[0], $this->imageFont[1], $this->imageFont[2] );
					if ( $string['font'] != '' )
					{
						$font = $string['font'];
					}
					if ( $string['size'] != 0 )
					{
						$size = $string['size'];
					}
					
					// Get the height and length of a custom font.
					if ( !is_int( $font ) )
					{
						$length = imagettfbbox( $size, 0, $font, $string['string'] );
					}
					
					// Set the appropriate text height.
					$this->imageH = ( is_int( $font ) ? imagefontheight( $font ) : ( $length[1] - $length[7] ) + 2 );
					
					// Add a margin if this is the first row.
					if ( (int) $this->imageY == 0 )
					{
						$this->imageY = $this->imageBorder[0] - 1;
					}
					
					// Check to see if a new row has been initiated.
					if ( is_array( $this->imageRows ) && array_key_exists( ( $key - 1 ), $this->imageRows ) )
					{
						$this->imageX = 0;
						$this->imageW = $this->imageBorder[0] + 2;
						$this->imageY += $this->imageH + $this->imageRows[( $key - 1 )];
					}
					
					// Check to see if a new space has been initiated.
					if ( is_array( $this->imageSpaces ) && array_key_exists( ( $key - 1 ), $this->imageSpaces ) )
					{
						$this->imageX += ( $this->imageSpaces[( $key - 1 )] );
					}
					
					// Set the appropriate text positions.
					$this->imageX = (int) $string['x'] > 0 ? (int) $string['x'] : (int) $this->imageX + (int) $this->imageW;
					$this->imageY = (int) $string['y'] > 0 ? (int) $string['y'] : (int) $this->imageY;
					// Set the appropriate text width.
					$this->imageW = ( is_int( $font ) ? imagefontwidth( $font ) * ( strlen( $string['string'] ) + 1 ) : $length[2] + 1 );
					
					list( $RED, $GREEN, $BLUE, $BLACK ) = $this->_convertColour( $string['colour'] != '#000000' ? $string['colour'] : ( isset( $colour ) ? $colour : '#000000' ) );
					switch( is_int( $font ) )
					{
						case TRUE:
							if ( $string['shadow'] == 1 )
							{
								imagestring( $this->instance, 2, $this->imageX + 1, $this->imageY + 1, $string['string'], imagecolorallocate( $this->instance, $BLACK, $BLACK, $BLACK ) );
								imagestring( $this->instance, 2, $this->imageX - 1, $this->imageY - 1, $string['string'], imagecolorallocate( $this->instance, $BLACK, $BLACK, $BLACK ) );
							}
							imagestring( $this->instance, 2, $this->imageX, $this->imageY, $string['string'], imagecolorallocate( $this->instance, $RED, $GREEN, $BLUE ) );
							break;
						
						case FALSE:
							if ( $string['shadow'] == 1 )
							{
								imagettftext( $this->instance, $size, 0, $this->imageX + 1, $this->imageY + 11, imagecolorallocate( $this->instance, $BLACK, $BLACK, $BLACK ), $font, $string['string'] );
							}
							imagettftext( $this->instance, $size, 0, $this->imageX, $this->imageY + 10, imagecolorallocate( $this->instance, $RED, $GREEN, $BLUE ), $font, $string['string'] );
							break;
					}
				}
			}
		
			// Render all of the icons.
			if ( is_array( $this->imageIcons ) )
			{
				foreach( $this->imageIcons as $key => $icon )
				{
					list( $width, $height ) = getimagesize( $icon['path'] );
					switch( $icon['extension'] )
					{
						case 'png':
							$instance = imagecreatefrompng( $icon['path'] );
							break;
		
						case 'gif':
							$instance = imagecreatefromgif( $icon['path'] );
							break;
		
						case 'jpg':
						case 'jpeg':
							$instance = imagecreatefromjpeg( $icon['path'] );
							break;
					}
					imagecopyresampled( $this->instance, $instance, $icon['x'], $icon['y'], 0, 0, $width, $height, $width, $height );
				}
			}
			
			if ( is_resource( $this->instance ) && (int) ob_get_length( ) === 0 )
			{
				if ( !isset( $savePath ) || $this->cache == 0 )
				{
					header( 'Content-Type: image/png' );
					$savePath = '';
				}
				imagepng( $this->instance, $savePath, 9 );
				if ( isset( $savePath ) )
				{
					chmod( $savePath, 0777 );
				}
			}
		}
		
		
		/**
		 * Convert RGB colours to HEX format
		 *
		 * @param string $colour
		 * @access private
		 * @return boolean/object
		**/
		private function _convertColour( $colour )
		{
			$colour = preg_replace( '/#/', NULL, $colour );
			if ( strlen( $colour ) != 6 && !preg_match( '/^([0-9])+$/', $colour ) )
			{
				$colour = '000000';
			}
			return array( hexdec( substr( $colour, 0, 2 ) ), hexdec( substr( $colour, 2, 2 ) ), hexdec( substr( $colour, 4, 2 ) ), hexdec( 00 ) );
		}
	}
	
	
	
	
	class ImageDraw_Image
	{
		protected $parent;
		
		
		/**
		 * @param instance $parent
		 * @access public
		 * @return null
		**/
		public function __construct( $parent )
		{
			$this->parent = $parent;
		}
		
		
		/**
		 * Apply the width & height for the object
		 *
		 * @param integer $width
		 * @param string $height
		 * @access public
		 * @return instance
		**/
		public function applySize( $width, $height )
		{
			$this->parent->imageWidth = (int) $width == $width ? $width : 120;
			$this->parent->imageHeight = (int) $height == $height ? $height : 60;
			
			return $this->parent->instance;
		}
		
		
		/**
		 * Apply the width & height by determening the length of a string using a custom font
		 *
		 * @param string $font
		 * @param integer $size
		 * @param string $string
		 * @param integer $extraWidth
		 * @param integer $extraHeight
		**/
		public function applySizeByFont( $font, $size, $string, $extraWidth = 10, $extraHeight = 10 )
		{
			// Make sure the text font is found.
			if ( !is_int( $font ) && !is_file( $font ) )
			{
				throw new Exception( 'The custom font face was not found, please double-check the location of it.' );
			}
			
			list( $whatever, $height, $width ) = imagettfbbox( $size, 0, $font, $string );
			$this->applySize( $width + (int) $extraWidth, $height + (int) $extraHeight );
			
			$this->parent->imageFont[0] = $font;
			$this->parent->imageFont[1] = (int) $size == $size ? $size : 11;
			
			return $this->parent->instance;
		}	
		
		
		/**
		 * Apply a background colour for the object
		 *
		 * @param string $colour
		 * @access public
		 * @return instance
		**/
		public function applyColour( $colour )
		{
			// Check if a background image has already been set.
			if ( $this->parent->imageBackground )
			{
				throw new Exception( 'You may not apply a background colour in case a background image has already been set.' );
			}
			
			// Make sure a width and height has been set.
			if ( !$this->parent->imageWidth || !$this->parent->imageHeight )
			{
				throw new Exception( 'You must set the image dimensions before attempting to set its background colour.' );
			}
			
			// Check if background transparency has been set.
			if ( $this->parent->imageTransparency )
			{
				throw new Exception( 'You may not apply a background colour in case a transparent background has already been set.' );
			}
			
			$this->parent->imageColour = $colour;
			return $this->parent->instance;
		}
		
		
		/**
		 * Apply a transparent background for the object
		 *
		 * @access public
		 * @return instance
		**/
		public function applyTransparency( )
		{
			// Make sure a width and height has been set.
			if ( !$this->parent->imageWidth || !$this->parent->imageHeight )
			{
				throw new Exception( 'You must set the image dimensions before attempting to set its background to transparent.' );
			}
			
			// Check if a background image has already been set.
			if ( $this->parent->imageBackground )
			{
				throw new Exception( 'You may not apply a transparent background in case a background image has already been set.' );
			}
			
			// Check if background colour has been set.
			if ( $this->parent->imageColour )
			{
				throw new Exception( 'You may not apply a transparent background in case a background colour has already been set.' );
			}
			
			$this->parent->imageTransparency = TRUE;
			return $this->parent->instance;
		}
		
		
		/**
		 * Apply a background image for the object
		 *
		 * @access public
		 * @return instance
		**/
		public function applyBackground( $background )
		{
			// Check if background colour has been set.
			if ( $this->parent->imageColour )
			{
				throw new Exception( 'You may not apply a background image in case a background colour has already been set.' );
			}
			
			// Check if background transparency has been set.
			if ( $this->parent->imageTransparency )
			{
				throw new Exception( 'You may not apply a background image in case a transparent background has already been set.' );
			}
			
			$this->parent->imageBackground = $background;
			$this->parent->imageExtension = strtolower( pathinfo( $this->parent->imageBackground, PATHINFO_EXTENSION ) );
			return $this->parent->instance;
		}
		
		
		/**
		 * Draw a border around an object
		 *
		 * @param integer $thickness
		 * @param string $colour
		 * @access public
		 * @return instance
		**/
		public function applyBorder( $thickness = 1, $colour = '#000000' )
		{
			// Make sure an image has been created.
			if ( !$this->parent->imageBackground && !$this->parent->imageColour && !$this->parent->imageTransparency )
			{
				throw new Exception( 'You must set the image background before attempting to apply a border to it.' );
			}
			
			$this->parent->imageBorder = array( (int) $thickness, $colour );
			$this->parent->imageX += $thickness + 2;
			return $this->parent->instance;
		}
		
		
		/**
		 * Add a font-style to the strings
		 *
		 * @param mixed $font
		 * @param integer $size
		 * @param string $colour
		 * @access public
		 * @return instance
		**/
		public function applyFont( $font, $size = 11, $colour = '#000000' )
		{
			// Make sure an image has been created.
			if ( !$this->parent->imageBackground && !$this->parent->imageColour && !$this->parent->imageTransparency )
			{
				throw new Exception( 'You must set the image background before attempting to apply a font to it.' );
			}
			
			// Make sure the text font is between 1 and 5 if it is an integer.
			if ( is_int( $font ) && !in_array( $font, range( 1, 5 ) ) )
			{
				throw new Exception( 'The font face must be between 1 and 5 (unless a custom font style).' );
			}
			
			// Make sure the text font is found.
			if ( !is_int( $font ) && !is_file( $font ) )
			{
				throw new Exception( 'The custom font face was not found, please double-check the location of it.' );
			}
			
			$this->parent->imageFont[0] = $font;
			$this->parent->imageFont[1] = (int) $size == $size ? $size : 11;
			$this->parent->imageFont[2] = $colour;
			return $this->parent->instance;
		}
		
		
		/**
		 * Add a string to the draw queue
		 *
		 * @param string $string
		 * @param integer $x
		 * @param integer $y
		 * @param boolean $shadow
		 * @param string $colour
		 * @access public
		 * @return instance
		**/
		public function applyString( $string, $x = 0, $y = 0, $shadow = TRUE, $colour = '#000000', $font = NULL, $size = 0 )
		{
			// Make sure an image has been created.
			if ( !$this->parent->imageBackground && !$this->parent->imageColour && !$this->parent->imageTransparency )
			{
				throw new Exception( 'You must set the image background before attempting to apply a string to it.' );
			}
			
			$this->parent->imageStrings[] = array(
				'string' => $string,
				'x' => (int) $x,
				'y' => (int) $y,
				'shadow' => (int) $shadow,
				'colour' => $colour,
				'font' => $font,
				'size' => $size
			);
			return $this->parent->instance;
		}
		
		
		/**
		 * Add an image to the draw queue
		 *
		 * @param string $icon
		 * @param integer $x
		 * @param integer $y
		 * @access public
		 * @return instance
		**/
		public function applyIcon( $icon, $x = 10, $y = 10 )
		{
			// Make sure an image has been created.
			if ( !$this->parent->imageBackground && !$this->parent->imageColour && !$this->parent->imageTransparency )
			{
				throw new Exception( 'You must set the image background before attempting to apply an icon to it.' );
			}
			
			// Make sure the icon exists.
			if ( !is_file( $icon ) )
			{
				throw new Exception( 'The icon was not found, please double-check the location of it.' );
			}
			
			$this->parent->imageIcons[] = array(
				'path' => $icon,
				'extension' => strtolower( pathinfo( $icon, PATHINFO_EXTENSION ) ),
				'x' => (int) $x,
				'y' => (int) $y
			);
			return $this->parent->instance;
		}
		
		
		/**
		 * Apply a spacer inbetween strings/icons
		 *
		 * @param integer $space
		 * @access public
		 * @return instance
		**/
		public function applySpacer( $space = 0 )
		{
			$key = key( array_slice( $this->parent->imageStrings, -1, 1, TRUE ) );
			$this->parent->imageSpaces[$key] = (int) $space;
			return $this->parent->instance;
		}
		
		
		/**
		 * Break the current row
		 *
		 * @param integer $space
		 * @access public
		 * @return instance
		**/
		public function breakRow( $space = 0 )
		{
			$key = key( array_slice( $this->parent->imageStrings, -1, 1, TRUE ) );
			$this->parent->imageRows[$key] = (int) $space;
			return $this->parent->instance;
		}
		
		
		/**
		 * Call the original build method
		 *
		 * @access public
		 * @return null
		**/
		public function build( )
		{
			$this->parent->build( );
		}
	}
	
	
	
	
	
	
	
	
	
	class ImageDraw_Cache
	{
		protected $parent;
		
		
		/**
		 * @param instance $parent
		 * @access public
		 * @return null
		**/
		public function __construct( $parent )
		{
			$this->parent = $parent;
		}
		
	
		/**
		 * Sets a filename for the cache outcome
		 *
		 * @param string $file
		 * @access public
		 * @return instance
		**/
		public function setFile( $file )
		{	
			$this->parent->cacheFile = preg_replace( '/([^a-z0-9-])/i', '', str_replace( ' ', '-', $file ) ).'.png';
			return $this->parent->instance;
		}
		
	
		/**
		 * Sets the amount of seconds it takes before the cache renews itself
		 *
		 * @param integer $seconds
		 * @access public
		 * @return instance
		**/
		public function setTime( $seconds )
		{
			$this->parent->cacheExpire = $seconds;
			return $this->parent->instance;
		}
		
		
		/**
		 * Sets the cache directory
		 *
		 * @param integer $time
		 * @access public
		 * @return instance
		**/
		public function setDirectory( $directory )
		{
			$this->parent->cacheDirectory = $directory;
			return $this->parent->instance;
		}
		
		
		/**
		 * Determine whether to update an existing file or not
		 *
		 * @access public
		 * @return boolean
		**/
		public function hasExpired( )
		{
			// Make sure the expire time has been set.
			if ( !isset( $this->parent->cacheExpire ) )
			{
				throw new Exception( 'You must set the expire time before attempting to run any of the cache methods.' );
			}
			
			// Make sure a valid directory has been set.
			if ( !is_dir( $this->parent->cacheDirectory ) )
			{
				throw new Exception( 'You must set a valid directory before attempting to run any of the cache methods.' );
			}
			
			// Check if the file needs to be updated.
			$file = $this->parent->cacheDirectory.$this->parent->cacheFile;
			if ( is_file( $file ) && time( ) < ( filemtime( $file ) + $this->parent->cacheExpire ) )
			{
				return FALSE;
			}
			return TRUE;
		}
		
		
		/**
		 * Load a cache file
		 *
		 * @access public
		 * @return null
		**/
		public function loadCache( )
		{
			// Make sure the expire time has been set.
			if ( !isset( $this->parent->cacheExpire ) )
			{
				throw new Exception( 'You must set the expire time before attempting to run any of the cache methods.' );
			}
			
			// Make sure a valid directory has been set.
			if ( !is_file( $this->parent->cacheDirectory.$this->parent->cacheFile ) )
			{
				throw new Exception( 'You must set a valid directory/file before attempting to run any of the cache methods.' );
			}
			
			if ( (int) ob_get_length( ) === 0 )
			{
				header( 'Content-Type: image/png' );
				echo file_get_contents( $this->parent->cacheDirectory.$this->parent->cacheFile );
			}
		}
		
		
		/**
		 * Saves a cache file
		 *
		 * @access public
		 * @return null
		**/
		public function saveCache( )
		{
			// Make sure the expire time has been set.
			if ( !isset( $this->parent->cacheExpire ) )
			{
				throw new Exception( 'You must set the expire time before attempting to run any of the cache methods.' );
			}
			
			// Make sure a valid directory has been set.
			if ( !is_dir( $this->parent->cacheDirectory ) )
			{
				throw new Exception( 'You must set a valid directory before attempting to run any of the cache methods.' );
			}
			
			$this->parent->build( $this->parent->cacheDirectory.$this->parent->cacheFile );
		}
	}
	
	ob_end_flush( );
	
?>

Someone? :D
 
Appearantly the script already works like that. But nobody told me :(

If you have custom items, you dont have to change the tibia.dat or spr. You can simply go to htdoc/public/images/items and create the item ID.
So this problem is solved and can be closed (Im such a newb :P)
 
Status
Not open for further replies.
Back
Top