Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 03-30-2004, 10:54 AM   #1
Beta Member
Join Date: Mar 2004
Posts: 2
Default PHP image.


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?


Nasimov is offline   Reply With Quote
Old 03-30-2004, 02:59 PM   #2
Site Team
root's Avatar
Join Date: Mar 2004
Posts: 8,107

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.
$file = "/path/to/file.txt";
$link = fopen($file, "r");
$contents = fread($link, filesize($file));
//$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); }

root is offline   Reply With Quote
Old 03-30-2004, 04:17 PM   #3
Site Team
David Lindon's Avatar
Join Date: Dec 2002
Posts: 15,233
Default Re: PHP image.

Wow, very interesting! Thanks.
[url=https://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 09:36 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0