Results 1 to 5 of 5

Thread: GD Align

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

    Latest Awards:

    Question GD Align

    If i wanted to align some text in a GD image to the right so that it expanded to the left like a word doc. Like so,
    Normal GD:
    Hai

    Right align:
    Hai


    I'm guessing I have to get the width of each character and then the number of characters and then subtract that from the point where I want to align it to? If so can I get some help writing that into a GD document.

    Thanks.
    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.

  2. #2
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:


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

    Latest Awards:

    Default

    Yeah, I've seen that, but thats for center alignment.

    To be honest their source doesn't even work:
    Code:
    <?php
    // ######################################
    // This was written by Michael Morgan of
    // CodingTuts (http://www.codingtuts.com)
    // ######################################
    
    // Some basic setup
    $imageWidth = 300;
    $imageHeight = 200;
    $textFont = "Cyclo.ttf";
    $textSize = 15;
    $textString = "CodingTuts.com";
    
    // Set the headers content type
    header("Content-type: image/png");
    
    // Create the image
    $image = imagecreatetruecolor($imageWidth, $imageHeight);
    
    // Create some colors
    $white = imagecolorallocate($image, 255, 255, 255);
    $black = imagecolorallocate($image, 0, 0, 0);
    
    // Fill the background of our image
    imagefilledrectangle($image, 0, 0, $imageWidth, $imageHeight, $black);
    
    // Get box info
    $box = imagettfbbox($textSize, 0, $textFont, $textString);
    
    //Find out the width and height of the text box
    $textW = $box[2] - $box[0];
    $textH = $box[5] - $box[3];
    
    // Calculate the positions
    $positionLeft = ($imageWidth - $textW)/2;
    $positionTop = (($imageHeight - $textH)/2);
    
    // Add some text
    imagettftext($image, $textSize, 0, $positionLeft, $positionTop, $white, $textFont, $textString);
    
    // Output the image to the browser
    imagepng($image);
    
    // Destroy the image
    imagedestroy($image);
    ?>
    Last edited by Verrou; 23-12-2008 at 08:09 PM.
    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.

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

    Latest Awards:

    Default

    Ok sorry for double post, I can't edit the above. Have figured out how to do the right alignment, thanks to the article provided by Jackboy +rep. Now does anyone know how to make it so that at a certain amount of characters/letters it enters a line space and continues on the next line?
    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.

  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    PHP Code:
    $string wordwrap$string15 ); 
    Replace 15 with the length of the string that you would like to break, it will replace it with '\n' and start a new line.

    (this will break in the middle of sentences though, so be careful on breaking words)

Posting Permissions

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