for the search, my way to preload images! haha

Search for in

Creating "Your IP is" images

PHP Coding Tutorials | Submited May 12, 2008

Written by: User Picture..

This shows you how to create the all-too-popular "Your IP is" banners that a lot of people have in their signatures.

Notes

User Picture..


This is just a basic guide, it leaves much to be desired, but that's a good thing, no?
Anyways, it's pretty simple, and if you don't get it you can just tinker with the full script included at the bottom.
Note: I just did this last night, so feel free to point out any inaccuracies.

Step One - Header


For step one, obviously, we open the PHP tags, and set the header to image, other wise it just won't work right.

<?php

header ('Content-type: image/png');

I'm not going to explain things that are obvious, which "image/png" is, right?

Step Two - Variables


This is where we'll create the variables to make the script less cluttered.

$doImage = imageCreateFromPNG('http://sevenbeasts.com/banner.png');
$color = ImageColorAllocate ($doImage, 136, 136, 136);
$ip = $_SERVER['REMOTE_ADDR'];

$doImage is what we base the image off, I used a simple black square, nothing too fancy.
$color is the colors we'll use, I used #555, which in RGB values converts to 136, 136, 136.
$ip is simply what detects the IP address

Step Three - Compile the Image


Here we'll put the variables to use with PHP image functions:

ImageString ($doImage, 2, 25, 5, "Your IP is $ip", $color);
ImageString ($doImage, 2, 65, 16, "I pwn DanaSoft", $color);
ImagePng ($doImage);
ImageDestroy ($doImage);

?>

ImageString(1) is like this:
Use the black banner, text size is 2, place it 25px from the left, 5px from the top, use text "Your IP is [IP VAR], and $color is #555.
The second one works in that same pattern.

ImagePNG confirms that the image is, in fact, PNG.

Does ImageDestroy really need to be explained?

?> is the clsing PHP tag. You didn't even remember we opened it, did you? -_-

All-together



<?php

Header ("Content-type: image/png");
$doImage = imageCreateFromPNG("http://sevenbeasts.com/banner.png");
$color = ImageColorAllocate ($doImage, 136, 136, 136);
$ip = $_SERVER['REMOTE_ADDR'];
ImageString ($doImage, 2, 25, 5, "Your IP is $ip", $color);
ImageString ($doImage, 2, 65, 16, "I pwn DanaSoft", $color);
ImagePng ($doImage);
ImageDestroy ($doImage);

?>

tags Tags: ip php create images

0Thumbs up  Thumbs down0

Related Tutorials
Adding Glitter to Images
Images in HTML
Text / Image Reflection
Myspace URL box images
Resize comment images [skem9]
Query Strings
Randomness with PHP
PSP : MAKING IMAGES TRANSPARENT (TUT 2)
PSP : MAKING IMAGES TRANSPARENT (TUT 3)
How to get Header images in a Friendster Layout
Alternative to if /else statements
Creating "Your IP is" images
Banning IPs
Random Images
No Comments Found
Sorry, you have to be a member to comment tutorials