Ever seen one of those cool forum signatures that display your IP address? Ever want to make one? Well, in this tutorial we’ll cover how to make one.
First off, lets set up our header and image size.
Now we can call up our colors. In this case I'm using white and black//Our colors (the image uses white) $black = imagecolorallocate($image, 255, 255, 255); $white = imagecolorallocate($image, 0, 0, 0);
Notice how it uses RGB instead of Hex color codes.
The way the PHP GD library works, we need to specify a font. Unlike in CSS though, we actually have to have the font uploaded on the host. So I downloaded a font from DaFont.com and uploaded it the main directory.$font = 'digital-7';
Now we can write text to the image.//Putting the text on the image imagettftext($image, 15, 0, 4, 18, $white, $font, 'Your IP:'); imagettftext($image, 15, 0, 75, 18, $white, $font, $_SERVER['REMOTE_ADDR']);
To finish it off//Finishing up imagepng($image); //Cleaning up imagedestroy($image); ?>
The finished product looks like this:
The final code looks like this: