Guest User

Untitled

a guest
Jun 19th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2. class fontGenerator
  3. {
  4. private $face;
  5. private $size;
  6. private $width;
  7. private $height;
  8. private $text = array();
  9.  
  10. function __construct( $face, $size, $lSpacer = 0 )
  11. {
  12. header( 'Content-Type: image/png' );
  13.  
  14. $this->face = $face;
  15. $this->size = $size;
  16. $this->width = $lSpacer;
  17.  
  18. return true;
  19. }
  20.  
  21. public function addText( $str, $colour )
  22. {
  23. $this->text[] = array( $str, $colour, $this->width );
  24. $arr = imagettfbbox( $this->size, 0, $this->face, $str );
  25. $this->width = abs( $this->width + $arr[ 4 ] );
  26. $this->height = abs( $arr[ 5 ] - $arr[ 1 ] );
  27.  
  28. return true;
  29. }
  30.  
  31. public function generateText()
  32. {
  33. $holder = imagecreatetruecolor( $this->width, $this->height );
  34. imagesavealpha( $holder, true );
  35. imagefill( $holder, 0, 0, imagecolorallocatealpha( $holder, 0, 0, 0, 127 ) );
  36.  
  37. foreach( $this->text as $text )
  38. {
  39. $e_colour = explode( ',', $text[ 1 ] );
  40. $colour = imagecolorallocate( $holder, $e_colour[ 0 ], $e_colour[ 1 ], $e_colour[ 2 ] );
  41. imagettftext( $holder, $this->size, 0, $text[ 2 ], $this->size - ( $this->size / 20 ), $colour, $this->face, $text[ 0 ] );
  42. }
  43.  
  44. imagepng( $holder );
  45. imagedestroy( $holder );
  46.  
  47. }
  48. }
  49.  
  50. $fontGenerator = new fontGenerator( 'ARIALNBI.TTF', 150 , 50 );
  51. $fontGenerator->addText( 'Hello ', '1,152,235' );
  52. $fontGenerator->addText( 'james', '70,70,70' );
  53. $fontGenerator->generateText();
Add Comment
Please, Sign In to add comment