Results 1 to 4 of 4

Thread: PHP image text

  1. #1
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default PHP image text

    A small script that uses php to make text based images. EX:
    http://www.domain.com/test/index.php?text=MY_TEXT
    would show up with a png or jpg saying "MY_TEXT".

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Take a look at this:
    http://us2.php.net/manual/en/function.imagecreate.php

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    Thank you!!! I edited the file a bit to work out just in case u wanted to know.
    Code:
    <?php
    header("Content-type: image/png");
    $im = @imagecreate(110, 20)
        or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 0, 0, 0);
    $text_color = imagecolorallocate($im, 233, 14, 91);
    $text = $_GET["text"];
    imagestring($im, 1, 5, 5,  $text, $text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    index.php?text=texthere

  4. #4
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    actually, one more thing. If my the text is longer than the image it doesnt expand the image it just kinda runs off the edge. How ould I fix this?

    Code:
    <?php
    header("Content-type: image/png");
    $im = @imagecreate(100, 15)
        or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 142, 72, 151);
    $text_color = imagecolorallocate($im, 0, 0, 0);
    $text = $_GET["text"];
    imagestring($im, 3, 1, 1,  $text, $text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    EDIT>
    Just like always i figured it out. heres my solution.
    <?php
    header("Content-type: image/png");
    //Ben's Inserts
    $text = $_GET["text"];
    $str = strlen($text);
    $str2 = 7;
    $total = $str * $str2;
    //End Bens inserts
    $im = @imagecreate($total, 15)
    or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 142, 72, 151);
    $text_color = imagecolorallocate($im, 0, 0, 0);
    imagestring($im, 3, 0, 0, $text, $text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    I seen that each character takes up 7 pixels including a space. So it takes the string from the url and multiplies it by 7. haha!
    Last edited by benslayton; 05-19-2007 at 05:56 AM. Reason: problemo solved!!!

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
  •