PDA

View Full Version : HowTo: A random sig pic


World
01-18-2010, 12:51 PM
Hi there, I'm World, and I'm going to show you how to create a signature with random pictures. Like mine! It's as easy as 1-2-3.

So, what do we need? First, we start with a bit of webspace that supports php. If you don't have any, there are lots of free providers out there. I myself chose 000webhost.com, mostly by random chance.

Then, we need some files. You can create all these with the Windows editor. Anything fancier is probably going to put stuff in there we don't want, like Word.

Firstly, a file named ".htacces", in which we put
Redirect /avatar.gif /avatar.php
Should be obvious what that does.

Next, the "avatar.php".

<?php
include("list.php");
$filename = array_rand(array_flip($arr));
$im = file_get_contents($filename);
$ctype="image/png";
header("content-type: $ctype");
echo $im;
?>
If you know your php (or html), you'll notice that this will only work for .png-files. It's the only type I use, and thus I didn't bother to include support for multiple types. (Well, I tried for 5 minutes and decided not to bother when it didn't work.) You can change it to anything from "image/jpeg" to "image/gif", but if you want multiples, well... tough luck ;)

And, for one last file:
<?php
$directory = "pics/";
$arr = array();
$images = glob("" . $directory . "*.png");
foreach($images as $image)
{
$arr[] = $image;
}
?>
Here you can change the directory to whatever you want. I simply chose a sub directory called "pics". If you're changing the file type, you'll have to change it here as well.

So, put all this on the server as well as the pictures, add the IMG-tag with the relevant info into your sig, like so
http://worldofg.net84.net/avatar.gif
and there you are.

Mind the sizes of the pictures though, hueg pictures will result in infractions and whatnot.

If you find this to bothersome, send me the pics and I will hook you up. Or get the files here: http://worldofg.net84.net/avatar.zip