src/UI/Image/Captcha.php
public function generateImage( $word, $fileName = NULL )
	{
		if( !$this->font )
			throw new RuntimeException( 'No font defined' );
		if( !( is_array( $this->textColor ) && count( $this->textColor ) == 3 ) )
			throw new InvalidArgumentException( 'Text Color must be an Array of 3 decimal Values.' );
		if( !( is_array( $this->background ) && count( $this->background ) == 3 ) )
			throw new InvalidArgumentException( 'Background Color must be an Array of 3 decimal Values.' );

		$image		= imagecreate( $this->width, $this->height );
		$backColor	= imagecolorallocate( $image, $this->background[0], $this->background[1], $this->background[2] );
		$frontColor	= imagecolorallocate( $image, $this->textColor[0], $this->textColor[1], $this->textColor[2] );

		for( $i=0; $i<strlen( $word ); $i++ )
		{
			//  --  ANGLE  --  //
			$angle	= 0;
			if( $this->angle )
			{
				$rand	= 2 * rand() / getrandmax() - 1;											//  randomize Float between -1 and 1
				$angle	= round( $rand * $this->angle, 0 );											//  calculate rounded Angle
			}

			//  --  POSITION X  --  //
			$offset	= 0;
			if( $this->offsetX )
			{
				$rand	= 2 * rand() / getrandmax() - 1;											//  randomize Float between -1 and 1
				$offset	= round( $rand * $this->offsetX, 0 );										//  calculate rounded Offset
			}
			$posX	= $i * 20 + $offset + 10;

			//  --  POSITION Y  --  //
			$offset	= 0;
			if( $this->offsetY )
			{
				$rand	= 2 * rand() / getrandmax() - 1;											//  randomize Float between -1 and 1
				$offset	= round( $rand * $this->offsetY, 0 );										//  calculate rounded Offset
			}
			$posY	= $offset + round( $this->height / 2, 0 ) + 5;

			$char	= $word[$i];
			imagettftext( $image, $this->fontSize, $angle, $posX, $posY, $frontColor, $this->font, $char );
		}
		ob_start();
		imagejpeg( $image, NULL, $this->quality );
		if( $fileName )
			return FS_File_Writer::save( $fileName, ob_get_clean() );
		return ob_get_clean();
	}
public function generateImage( $word, $fileName = NULL )
	{
		if( !$this->font )
			throw new RuntimeException( 'No font defined' );
		if( !( is_array( $this->textColor ) && count( $this->textColor ) == 3 ) )
			throw new InvalidArgumentException( 'Text Color must be an Array of 3 decimal Values.' );
		if( !( is_array( $this->background ) && count( $this->background ) == 3 ) )
			throw new InvalidArgumentException( 'Background Color must be an Array of 3 decimal Values.' );

		$image		= imagecreate( $this->width, $this->height );
		$backColor	= imagecolorallocate( $image, $this->background[0], $this->background[1], $this->background[2] );
		$frontColor	= imagecolorallocate( $image, $this->textColor[0], $this->textColor[1], $this->textColor[2] );

		for( $i=0; $i<strlen( $word ); $i++ )
		{
			//  --  ANGLE  --  //
			$angle	= 0;
			if( $this->angle )
			{
				$rand	= 2 * rand() / getrandmax() - 1;											//  randomize Float between -1 and 1
				$angle	= round( $rand * $this->angle, 0 );											//  calculate rounded Angle
			}

			//  --  POSITION X  --  //
			$offset	= 0;
			if( $this->offsetX )
			{
				$rand	= 2 * rand() / getrandmax() - 1;											//  randomize Float between -1 and 1
				$offset	= round( $rand * $this->offsetX, 0 );										//  calculate rounded Offset
			}
			$posX	= $i * 20 + $offset + 10;

			//  --  POSITION Y  --  //
			$offset	= 0;
			if( $this->offsetY )
			{
				$rand	= 2 * rand() / getrandmax() - 1;											//  randomize Float between -1 and 1
				$offset	= round( $rand * $this->offsetY, 0 );										//  calculate rounded Offset
			}
			$posY	= $offset + round( $this->height / 2, 0 ) + 5;

			$char	= $word[$i];
			imagettftext( $image, $this->fontSize, $angle, $posX, $posY, $frontColor, $this->font, $char );
		}
		ob_start();
		imagejpeg( $image, NULL, $this->quality );
		if( $fileName )
			return FS_File_Writer::save( $fileName, ob_get_clean() );
		return ob_get_clean();
	}
public function generateImage ( $ word , $ fileName = NULL ) { if ( ! $ this -> font ) throw new RuntimeException ( 'No font defined' ) ; if ( ! ( is_array ( $ this -> textColor ) && count ( $ this -> textColor ) == 3 ) ) throw new InvalidArgumentException ( 'Text Color must be an Array of 3 decimal Values.' ) ; if ( ! ( is_array ( $ this -> background ) && count ( $ this -> background ) == 3 ) ) throw new InvalidArgumentException ( 'Background Color must be an Array of 3 decimal Values.' ) ; $ image = imagecreate ( $ this -> width , $ this -> height ) ; $ backColor = imagecolorallocate ( $ image , $ this -> background [ 0 ] , $ this -> background [ 1 ] , $ this -> background [ 2 ] ) ; $ frontColor = imagecolorallocate ( $ image , $ this -> textColor [ 0 ] , $ this -> textColor [ 1 ] , $ this -> textColor [ 2 ] ) ; for ( $ i = 0 ; $ i < strlen ( $ word ) ; $ i ++ ) { //  --  ANGLE  --  //
 $ angle = 0 ; if ( $ this -> angle ) { $ rand = 2 * rand ( ) / getrandmax ( ) - 1 ; //  randomize Float between -1 and 1
 $ angle = round ( $ rand * $ this -> angle , 0 ) ; //  calculate rounded Angle
 } //  --  POSITION X  --  //
 $ offset = 0 ; if ( $ this -> offsetX ) { $ rand = 2 * rand ( ) / getrandmax ( ) - 1 ; //  randomize Float between -1 and 1
 $ offset = round ( $ rand * $ this -> offsetX , 0 ) ; //  calculate rounded Offset
 } $ posX = $ i * 20 + $ offset + 10 ; //  --  POSITION Y  --  //
 $ offset = 0 ; if ( $ this -> offsetY ) { $ rand = 2 * rand ( ) / getrandmax ( ) - 1 ; //  randomize Float between -1 and 1
 $ offset = round ( $ rand * $ this -> offsetY , 0 ) ; //  calculate rounded Offset
 } $ posY = $ offset + round ( $ this -> height / 2 , 0 ) + 5 ; $ char = $ word [ $ i ] ; imagettftext ( $ image , $ this -> fontSize , $ angle , $ posX , $ posY , $ frontColor , $ this -> font , $ char ) ; } ob_start ( ) ; imagejpeg ( $ image , NULL , $ this -> quality ) ; if ( $ fileName ) return FS_File_Writer :: save ( $ fileName , ob_get_clean ( ) ) ; return ob_get_clean ( ) ; }
Generates Captcha Image for Captcha Word.
Saves image if file name is set.
Otherwise returns binary content of image.
@access		public
@param		string		$word		Captcha Word
@param		string		$fileName	File Name to write Captcha Image to
@return		int
Generates Captcha Image for Captcha Word . Saves image if file name is set . Otherwise returns binary content of image .