[GD]Create An Image With Text
First off you will want to make a text file and name it stat.txt
On your server, it needs the CHMOD properties of 777 so that this script can write to it.
Next make a new file and name it image.php this will contain all the scripting necessary to create and show the image.
In this new file type up something like:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
require "config.php"; //get the config file
$message = file_get_contents($filename); //open the file and get its contents
$pic=ImageCreate($width,20); //width defined in the config and height of 20
$col1=ImageColorAllocate($pic,$c1r,$c1g,$c1b); //background color
$col2=ImageColorAllocate($pic,$c2r,$c2g,$c2b); //text color
$col3=ImageColorAllocate($pic,$c3r,$c3g,$c3b); //border color
ImageFilledRectangle($pic, 0, 0, $width, 20, $col3); //border
ImageFilledRectangle($pic, 1, 1, $width-2, 18, $col2); //fill
ImageString($pic, 3, 5, 2, $message, $col1); //text
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //expirey date
Header("Content-type: image/png"); //change content type
ImagePNG($pic); //create the picture
ImageDestroy($pic); //destroy it
?>
Normally, forums and websites will not let you use .php extensions for images therefore you should open up your .htaccess file and in it add:
Code
RewriteEngine On
RewriteRule ^gd_img.png$ image.php
This will fake out the forum or website into believing that it is a true image.
Now that that is done you need to create the file: config.php and in it type something like the following:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?
// Configuration File
// Modify the values to work for you
// Name of the file where the message is
// Was originally stat.txt
$filename="stat.txt";
// Width of the image
$width=300;
// Color of the background
//c1r is red value, c1g is green, c1b is blue
//values from 0 to 255
$c1r=0;
$c1g=0;
$c1b=0;
// Color of the text
//c2r is red value, c2g is green, c2b is blue
//values from 0 to 255
$c2r=255;
$c2g=255;
$c2b=255;
// Color of the border
//c3r is red value, c3g is green, c3b is blue
//values from 0 to 255
$c3r=0;
$c3g=128;
$c3b=0;
// Secret code to access edit.php
$sc="mypasswordgoeshere121";
?>
Thats that file, this is where the edit file, and the image file will pull information to create and edit the image.
Next create one last file and name it: edit.php
In this file you will be able to edit what the image says.
Now, open it up and type up something like:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?
require "config.php"; //get config
if($_POST['sc']!=$sc) //if the posted password doesn't equal config return to form
{
echo "<form action='edit.php' method='post'>
New Message:<input type='text' name='new' /><br>
Password:<input type='password' name='sc' /><br>
<input type='submit' value='Enter' />
</form>\n
"; //the form
}else{ //else...
$file = fopen($filename,'w'); //open the file
fwrite($file,$_POST['new']); //write to the file
echo "Modified<br><br><img src='image.php' alt='".$_POST['new']." />"; //success
} //end if
?>
If you encounter any problems please post them here :)