SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: GD help

  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    GD help

    Hey,

    I downloaded a script to turn some text into an image but I can't get it to work. Here is the script I have uploaded - http://djclan.auscstrike.com/image.php - and here is the code
    PHP Code:
    <?php
    function text2image($mytext,$imwidth,$imheight) {
     if (!empty(
    $mytext)) {
      if (empty(
    $imwidth)) $imwidth=500;
      if (empty(
    $imheight)) $imheight=400;
      
    Header("Content-type: image/Jpeg");
      
    $im = @ImageCreate ($imwidth=500$imheight) or die ("Cannot Initialize new GD image stream");
      
    $background_color ImageColorAllocate ($im255255255);
      
    $text_color ImageColorAllocate ($im000);
      
    $mytext stripslashes($mytext);
      
    $mytext ereg_replace("\r\n","\n",$mytext) ;
      
    $count=5;
      
    $returns explode("\n"$mytext);
      while(list(
    $k$mytext) = each($returns)) {
       
    $count $count;
       
    $insert_text substr($mytext0);
       
    ltrim($insert_text);
       
    ImageString ($im25,$count$insert_text$text_color);
       
    imagerectangle ($im22$imwidth-2$imheight-2$text_color);
       
    $count=$count+13;
      }
      
    ImageJpeg($im);
      
    ImageDestroy;
     }
    }
    text2image("Hello World"13020);
    ?>
    Anyone have any ideas?

    Thanks

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    $insert_text = substr($mytext, 0);

    Should that not be ...

    $insert_text = substr($returns, 0);

    ???
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one question.

    why are you using a string-line-break-write script to write 'hello world' on one line.

    try losing all the string manipulation first and see what happens. It is a lot easier to debug a bare-bones version than a bloated one.

    Header("Content-type: image/jpeg" );
    $im = @ImageCreate (300, 30);
    $background_color = ImageColorAllocate ($im, 255, 255, 255);
    $text_color = ImageColorAllocate ($im, 0, 0, 0);
    $mytext = 'Hello World';
    ImageString ($im, 2, 5, 5, $my_text, $text_color);
    ImageJpeg($im);
    ImageDestroy($im);
    teckis - that's news to me.

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    OK, I tried your code pootergeist and I've come to the conclusion that my host doesn't support GD

    I'm not sure why the code as bloated but I downloaded the script as I have no clue how to work any of the image functions.

    Thanks for the reply


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
  •