+ Reply to Thread
Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 51

Thread: PHP:Tutorial - Getting to know GD

  1. #21
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    hello! nice tutorial!! i was just wondering if you know how to wrap the text into a nice paragraph if the string is too long to fit onto the image?
    This, http://php.net/wordwrap, may helps you.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #22
    snailofsatan is offline Newbie
    Join Date
    May 2007
    Posts
    4
    Rep Power
    0
    sorry to be a pain, but i'm a bit new to this GD stuff! do you know how i can implement the php word wrap into the GD code below?

    <?php
    $text = "The quick brown fox jumped over the lazy dog.";
    $newtext = wordwrap($text, 20, "<br />\n");

    echo $newtext;
    ?>

    <?php
    header('Content-type: image/png');
    $text = $_GET['text'];

    $im = imagecreatefrompng ("userbar.png");

    $color = imagecolorallocate($im, 0, 0, 0);

    $font = 'font.ttf';
    $fontsize = 6;
    $size = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
    $dx = (imagesx($im)) - (abs($size[2]-$size[0])) - 20; //calculate the location to start the text
    imagettftext($im, $fontsize, 0, $dx, 13, $color, $font, $text);
    imagepng($im);
    imagedestroy($im);
    ?>
    thanks in advance for any help/tips!

    ps if i use $newtext in the GD code, won't it ignore the <br>s and /n's and just show the code as text? or will it process them and move down to a new line?
    kev
    Last edited by snailofsatan; 05-09-2007 at 05:15 AM. Reason: addition

  4. #23
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    I've no experience with PHP and GD, so it may be wrong.

    In your code, from PHP.net, you have first a variable, $text, with some text. hen your wordwraps it, and get a new text into the variable $newtext. In the other code, from this tutorial, you also need some text. The text is used in imagettfbbox() and imagettftext(). They both use the variable, $text, with is the content of the GET, "text". Because of that, you simply have to wordwrap that variable, and then then text of it will be used in the following code.

    Code:
    <?php
    header('Content-type: image/png');
    
    // ------------------------------------------------------
    // This is the changed line...
    $text = wordwrap($_GET['text'], 20, "<br />\n");
    // ------------------------------------------------------
    
    $im = imagecreatefrompng ("userbar.png");
    
    $color = imagecolorallocate($im, 0, 0, 0);
    
    $font = 'font.ttf';
    $fontsize = 6;
    $size = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
    $dx = (imagesx($im)) - (abs($size[2]-$size[0])) - 20; //calculate the location to start the text
    imagettftext($im, $fontsize, 0, $dx, 13, $color, $font, $text);
    imagepng($im);
    imagedestroy($im);
    ?>

  5. #24
    snailofsatan is offline Newbie
    Join Date
    May 2007
    Posts
    4
    Rep Power
    0
    thankyou i'll give it a whirl!!

  6. #25
    snailofsatan is offline Newbie
    Join Date
    May 2007
    Posts
    4
    Rep Power
    0
    oh no, almost! rather that making a new line where each <br> \n is.. it just shows that text.. (rather than processing it)

  7. #26
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31
    Very nice sidewinder, I'm impressed at the time you spent on that. Next up, you may want to dig into using PHP,GD, and Flash together. PHP can generate images using GD and then spice them up with the flash code PHP can create.

  8. #27
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    I've been looking into using flash with php, the only thing I've been able to come up with is outputting information using xml, and have a flash action script read the xml.

  9. #28
    sido is offline Newbie
    Join Date
    May 2007
    Posts
    2
    Rep Power
    0
    To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
    so.. let's try it... but looks very interesting.

  10. #29
    angusi is offline Newbie
    Join Date
    Jun 2007
    Posts
    1
    Rep Power
    0
    nice tut, just need to try it out now

  11. #30
    seozus Guest
    Real nice tutorial, this site is a real discovery

+ Reply to Thread
Page 3 of 6 FirstFirst 12345 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help with a VB tutorial please.
    By brap in forum Visual Basic Programming
    Replies: 0
    Last Post: 09-15-2010, 09:58 AM
  2. MPI tutorial
    By A-U-C-C in forum C and C++
    Replies: 1
    Last Post: 05-07-2010, 09:03 AM
  3. PHP Tutorial
    By Xav in forum PHP Development
    Replies: 0
    Last Post: 04-09-2008, 01:13 PM
  4. Need Help With Tutorial
    By gszauer in forum Java Help
    Replies: 2
    Last Post: 02-22-2008, 10:06 AM
  5. Hello, New and need a tutorial.
    By Cageman in forum C and C++
    Replies: 4
    Last Post: 12-12-2007, 11:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

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