This is php which belongs to web development so don't say it belongs to graphics.
This tutorial will do a image that displays own ip. Same as my signature has but without the background image.
I will explain everything about the code in this tutorial but if you only want the code its end of the tutorial.
To start, create a new file, and then add the php code tags
Then, we need to make the webpage tell the browser that this page is an image, so to do this, we would do:
Code:
header("Content-Type: image/png");
So lets start and make a new image:
Code:
$im = @imagecreate(400, 20)
or die("An error occured, try to refresh");
If an error occurs, it will come up with "An error occurred, try to refresh"
You can change the 400 to the width of the image and 20 to the height.
Next we will add in the background:
Code:
$background_color = imagecolorallocate($im, 0, 0, 0);
The 3 last numbers represent: Red, Green, Blue
in this case, its black.
And now we need to receive the IP of the user viewing the page:
Code:
$ip=$_SERVER['REMOTE_ADDR'];
Now we will set the color for the ip and for the author:
Code:
$text_color = imagecolorallocate($im, 0, 0, 255);
$author = imagecolorallocate($im, 255, 0, 0);
Now lets write the strings/information we have got:
Code:
imagestring($im, 1, 5, 5, "Your IP is: " . $ip, $text_color);
the $im is the image, the 1 represents the font, and after that, the 2 numbers are for the X and Y coordinates.
Last we will save the image to PNG and close the image:
Code:
imagepng($im);
imagedestroy($im);
Your final code should look now something like this:
Code:
<?php
header("Content-Type: image/png");
$im = @imagecreate(400, 20)
or die("An error occured, try to refresh");
$background_color = imagecolorallocate($im, 0, 0, 0);
$ip=$_SERVER['REMOTE_ADDR'];
$text_color = imagecolorallocate($im, 0, 0, 255);
$author = imagecolorallocate($im, 255, 0, 0);
imagestring($im, 1, 5, 5, "Your IP is: " . $ip, $text_color);
imagepng($im);
imagedestroy($im);
?>
Hope you'll like it, enjoy.