Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class fontGenerator
- {
- private $face;
- private $size;
- private $width;
- private $height;
- private $text = array();
- function __construct( $face, $size, $lSpacer = 0 )
- {
- header( 'Content-Type: image/png' );
- $this->face = $face;
- $this->size = $size;
- $this->width = $lSpacer;
- return true;
- }
- public function addText( $str, $colour )
- {
- $this->text[] = array( $str, $colour, $this->width );
- $arr = imagettfbbox( $this->size, 0, $this->face, $str );
- $this->width = abs( $this->width + $arr[ 4 ] );
- $this->height = abs( $arr[ 5 ] - $arr[ 1 ] );
- return true;
- }
- public function generateText()
- {
- $holder = imagecreatetruecolor( $this->width, $this->height );
- imagesavealpha( $holder, true );
- imagefill( $holder, 0, 0, imagecolorallocatealpha( $holder, 0, 0, 0, 127 ) );
- foreach( $this->text as $text )
- {
- $e_colour = explode( ',', $text[ 1 ] );
- $colour = imagecolorallocate( $holder, $e_colour[ 0 ], $e_colour[ 1 ], $e_colour[ 2 ] );
- imagettftext( $holder, $this->size, 0, $text[ 2 ], $this->size - ( $this->size / 20 ), $colour, $this->face, $text[ 0 ] );
- }
- imagepng( $holder );
- imagedestroy( $holder );
- }
- }
- $fontGenerator = new fontGenerator( 'ARIALNBI.TTF', 150 , 50 );
- $fontGenerator->addText( 'Hello ', '1,152,235' );
- $fontGenerator->addText( 'james', '70,70,70' );
- $fontGenerator->generateText();
Add Comment
Please, Sign In to add comment