Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default Font generator - php

    Made this up, thought i'd release it to you guis. Probably loads on teh internets.

    PHP Code:
    <?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 );

        }
    }
    usage:

    PHP Code:
    require 'fontgenerator.class.php';

    $fontGenerator = new fontGenerator( 'ARIALNI.TTF', 24 );
    /* fontGenerator( string font, int size, int leftspacer (optional) ); */
    $fontGenerator->addText( 'welcome ', '147,215,255' );
    /* addText( string text, string colour(RGB) ); */
    $fontGenerator->addText( 'james', '99,99,99' );
    $fontGenerator->generateText(); 
    Hi, names James. I am a web developer.

  2. #2
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default

    Not being a pain, but a working demo would be nice.
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  3. #3
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Hi, names James. I am a web developer.

  4. #4
    Join Date
    Nov 2005
    Posts
    4,486
    Tokens
    921

    Latest Awards:

    Default

    Quite nice, if I add a p though, the bottom gets cut off.
    "RETIRED" FROM HABBO(X)

    :¬:

    TOMSPIT / COWLY05


  5. #5
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    dear god, i'll fix the math when I get home, been so tired.
    Hi, names James. I am a web developer.

  6. #6
    Join Date
    May 2009
    Posts
    117
    Tokens
    0

    Default

    Quote Originally Posted by Protege View Post
    dear god, i'll fix the math when I get home, been so tired.
    Very well done sir
    you noa have permizionz to rule teh interwebz.

  7. #7
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    yea i do, suck my ****./
    Hi, names James. I am a web developer.

  8. #8
    Join Date
    Jun 2008
    Location
    West midlands, Birmingham.
    Posts
    2,093
    Tokens
    1,899

    Latest Awards:

    Default

    Lol ^

    Nice of you to release, should come in handy to someone.

  9. #9
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Fixed it, I believe anyway
    http://www.safeupload.com/Public/generate_text.php?Text=james|%20rozee%20is%20queer

    PHP Code:
    <?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 ] );
            
            
    $height = abs( $arr[ 5 ] - $arr[ 1 ] );
            
            if( 
    $this->height < $height )
            {
                
    $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 );

        }
    }
    generate_text.php
    PHP Code:
    <?php
    require_once 'generate.class.php';

    $fontGenerator = new fontGenerator( 'SEGOEUII.TTF', 24, 10 );

    $txt = $_GET[ 'Text' ];
    $e_txt = explode( '|', $txt );

    $fontGenerator->addText( $e_txt[ 0 ], '147,215,255' );
    $fontGenerator->addText( $e_txt[ 1 ], '99,99,99' );
    $fontGenerator->generateText();
    Last edited by Protege; 28-05-2009 at 07:35 AM.
    Hi, names James. I am a web developer.

  10. #10
    Join Date
    Oct 2006
    Posts
    2,918
    Tokens
    946
    Habbo
    Verrou

    Latest Awards:

    Default

    Last edited by Verrou; 28-05-2009 at 10:30 AM.
    Quote Originally Posted by Special-1k View Post
    How do you uninstall an internet? I want to uninstall my Google Chrome and
    get firefox but I never really got rid of an internet my dad usually did it for me.
    If you know how post below so I can do this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •