PDA

View Full Version : Random Image Signature


Vicious88
07-16-2009, 06:28 AM
If you haven't noticed already, I've updated my signature to display images of myself saying somewhat random things.

I did this with the help of a nifty script I found online. This script was originally designed by Matthey Mullenweg, and while it's a bit dated, really does the trick.

In order to use this guide, you're going to need some place online where you can store a bunch of images. Make sure that in this image directory, you put only the images you want to appear in your signature.

For me, I simply uploaded them to Infohub's server in a new directory called "v88". If you have a webserver of any kind (any basic hosting package would do -- I'd recommend geocities, but Yahoo is discontinuing later this year) you should be able to create a directory and store a handful of pictures in it.

Once you've got your images gathered up and hosted online in your directory, you're going to want to open up notepad and copy this basic script into it:

<?php
/*
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = '';

// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';

$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';

$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>

Make sure you save that script as a PHP file, for instance, "sig.php" or something of that sort. Please note that I've modified this script to make it shorter, but no functionality has been changed.

Now that you've got your PHP file made, simply upload it to the same directory as your images. This part of your setup is done, and the next part is ridiculously easy!

Go to the forums where you want to use your random image script, and add this line to your signature field:
<img scr="whereeveritisyourstuffishosted/sig.php" alt="Whatever you want the mouse-over to say" />

That's it! You're done!

Kudos to Matthew Mullengew (http://ma.tt/scripts/randomimage/) for this script. You've made the internet a better place.


F.A.Q.:

Q: The forum I'm wanting to use the random images at, won't let me post HTML in my signature -- is there a BBCode that will do the trick.
A: I haven't tried it yet, but you could see about putting the address of your PHP script in as the address of the [img] BBCode address.

Q: What do you mean I have to host the pictures online? Will tinypic, imageshack, or picoodle do?
A: No, you're going to need for all of your pictures to be online and in one folder, along with a PHP script. Most image hosting sites don't seperate images out into folders, and even those that do don't let you upload PHP scripts.

Q: Where can I host my images and script?
A: Pretty much any place that lets you build and host a cheesy little freebie website will do the trick. They'll provide you with a shared URL and online file hosting, so everything you need will be right there at your finger tips.

Q: I want different forums to pull from different images, can I do this?
A: Yep, just re-do everything in a different directory and point your signature at that new directory's PHP file.

Q: This seems difficult, is it?
A: Not at all, it only seems that way. Just copy and paste the script, get it all online, and point your signature at it.

Q: My signature's images are all different sizes -- will this re-size them.
A: Nope - you're going to have to do a little photo editing if you want a smooth consistant image size or quality.

Flozz
07-16-2009, 04:34 PM
nice im going to try this!

Vicious88
07-16-2009, 08:38 PM
It also works with the BBCode's [IMG] Tag!

Flozz
07-17-2009, 12:20 PM
i tried it and seems to only show the actual code not the image i renamed it to sig.php and put all the images in the right place

Vicious88
07-17-2009, 02:13 PM
Just to recap... You made sure the script is saved as sig.php and in the same online directory as the images right?

You may try using the BBCode for you signature:
['img]http://whereeveryourstuffisat.com/sig/sig.php[/img]

Be sure you remove that ' from the code or else it won't work.

Flozz
07-17-2009, 03:54 PM
http://www.dhost.info/flozz/Sig1/sig.php

well i got to the final stage!

sadly i cant post html and bb-code seems to not work
probably because of my host not wanting hotlinking
http://dhost.info/flozz/Sig1/sig.php

Vicious88
08-11-2009, 01:30 AM
As an update to this thread -- I've found a great host for small projects such as this: it's called drivehq.com and they offer free FTP servers - which is more or less exactly what you need.