PHP image.

Nasimov

Beta member
Messages
4
Hello!

I want to load text from a .txt file on the web and put it on to an image. How can I do that in php?

Thanks.
 
Hope this gives you some help..

You'll need to turn on the gd2 include in the php.ini file. and you'll need to make sure header are buffered, so that you can change them with the script,

Also when you copy this script, or any script whilst writting to an image output make sure you don't copy any white space around the <? ?> brackets, if you do it will break even though the code is correct.

(this will lead to much head scratching!)

Made this from two file I have lurking on my site, I've never really though of creating images from text file before so this is untested.
--------------------------------------------------------------
<?php
$file = "/path/to/file.txt";
$link = fopen($file, "r");
$contents = fread($link, filesize($file));
fclose($link);
//$contents conatins the text

header ("Content-type: image/png");
$im = @ImageCreateFromPNG ("php.png");
$img_handle = ImageCreate (351, 57) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
//set text colour
$txt_color = ImageColorAllocate ($img_handle, 255, 153, 51);

//the three numbers are as follow
//1st is font style 1-5
//2nd is x position, position from left hand margine
//third is y position, position from top
ImageString ($img_handle, 3, 5, 1, "$contents", $txt_color);
//or put text in with text file text
ImageString ($img_handle, 3, 5, 13, "NAME = $contents", $txt_color);
//perhaps add footnotes
ImageString ($img_handle, 3, 5, 42, "- text from a picture creating script -", $txt_color);
ImagePng ($img_handle); }
?>
--------------------------------------------------------------------
 
Back
Top Bottom