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
Printable View
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
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..
demo of this script: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);
?>
this is the image it produces:
http://david.gamersepitome.net/files/php/img.php
this is the original image:
http://david.gamersepitome.net/files/php/image.png
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.
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: http://www.rappingreindeer.co.uk/9.php
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
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.
Here goes nothing
How exctly do I make it into a .png.
Edit http://rappingreindeer.co.uk/sign.php?png