Results 1 to 6 of 6

Thread: Php image

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    Php image

    Okay here it is:
    I want to load text from a .txt on the web and put it on to an image.
    Php is not my area of expertease
    Could someone please help.
    Thank you.

    --Mahony

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    well, do you already have an image and want to add onto it, or do you want to dynamically create an image and put the text on it? i'm just going to assume you already have a picture, and so i'll work from that..

    PHP Code:
    <?
        //set image and file paths
        $img_path = "image.png"; //image to add onto 
        $file_path = "text.txt"; //text file to open and add to image
        
        //open the base image 
        $img = imageCreateFromPNG($img_path);

        //make the colors to be used
        $black = imageColorAllocate($img, 0, 0, 0); //100% black for text
        
        //open the text file for reading
        $fopen = fopen($file_path, "r");
        //read the text file completely and store it in $text
        $text = fread($fopen, filesize($file_path));
        fclose($fopen);

        //*text properties*
          $font = "verdana.ttf"; //path to the font we're using
          $size = 12;            //text size
          $angle = 0;            //angle of text
          $pos['x'] = 65;        //position on the x axis
          $pos['y'] = 90;        //position on the y axis

        //add the text from the file to the image
        imageTTFText($img, $size, $angle, $pos['x'], $pos['y'], $black, $font, $text);

        //output the image to the browser
        imagePNG($img);    

        //destroy the image to restore memory
        imagedestroy($img);
    ?>
    demo of this script:

    this is the image it produces:


    this is the original image:


    this is the text file:
    http://david.gamersepitome.net/files/php/text.txt

    this is the font file:
    http://david.gamersepitome.net/files/php/verdana.ttf

    hope that can jump start you in some direction.. if you don't understand something in the script, ask for it to be explained.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4

    Thumbs up

    Thanks, that is a big help. I've been meaning to learn php for a while now, maybe I should learn :P

    Edit: "$file_path = "text.txt"; //text file to open and add to image"

    I tryed doing like http://www........com/file.txt

    But it didn't work the file is not on my server. How would I do that?

    Edit2:
    Last edited by Mahony; Feb 20th, 2004 at 01:28 PM.

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4
    Okay didn't exactly work right, how can I change the script so it loads a php file not a text, http://rappingreindeer.co.uk/yes.php

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    just change the file path to it and it will grab the text.. although, if it has HTML in that "yes.php", it will also grab that, so you'll have to remove the HTML or parse out the information you want.
    Like Archer? Check out some Sterling Archer quotes.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    4
    Here goes nothing


    How exctly do I make it into a .png.

    Edit
    Last edited by Mahony; Feb 20th, 2004 at 05:33 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width