|
-
Feb 19th, 2004, 04:35 PM
#1
Thread Starter
New Member
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
-
Feb 20th, 2004, 02:53 AM
#2
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.
-
Feb 20th, 2004, 11:30 AM
#3
Thread Starter
New Member
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.
-
Feb 20th, 2004, 01:31 PM
#4
Thread Starter
New Member
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
-
Feb 20th, 2004, 02:22 PM
#5
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.
-
Feb 20th, 2004, 05:04 PM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|