Jan 15
You can find an updated version of this script here.
Have you ever noticed on forums that some users’ avatars will be different each time the page reloads? I recently decided that I wanted to display multiple avatars on Snark, so I sat down and wrote this little script. (This method only works for forums that allow off-site avatars.)
Usage
First, create a folder on your server then upload your favorite avatars to that folder.
Copy and paste the following code into a .php file (you can name the file whatever you want):
<?php
/*******************************************************************************
* PHP AVATAR ROTATOR
*******************************************************************************/
$path = "/images/avatars/"; // Path to your avatar folder relative to the root directory of your site
/******************************************************************************
* DO NOT EDIT BELOW THIS LINE!
******************************************************************************/
$dir = $_SERVER['DOCUMENT_ROOT'].$path;
$avatars = array();
// Open avatar directory and read its contents into an array
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (filetype($dir.$file) == "file" && getimagesize($dir.$file)) {
array_push($avatars, $file);
}
}
closedir($dh);
}
}
// Create random avatar
$img = $dir.$avatars[rand(0, count($avatars)-1)];
$info = getimagesize($img);
if ($info[2] == 2) {
header('Content-Type: image/jpeg');
$img = imagecreatefromjpeg($img);
imagejpeg($img);
}
elseif ($info[2] == 3) {
header('Content-Type: image/png');
$img = imagecreatefrompng($img);
imagepng($img);
}
else {
header('Content-Type: image/gif');
$img = imagecreatefromgif($img);
imagegif($img);
}
imagedestroy($img);
?>
Be sure to change $path (on line 6) to the appropriate value (the path to your avatar folder relative to your site’s root directory).
After you upload the .php file you created to your server, the avatar rotation is available for use. In your forum’s profile control panel, type the URL of the file in the appropriate field. Example URL:
http://bubblessoc.net/images/rotator.php
Notes
- Only .gif, .jpg, .png images allowed.
- Other than making sure that the file is a valid image, this example does not check for errors.
- Check to make sure that your forum allows avatar rotations before using
Click here to see my avatar rotation
Hev (Quote, )
Oh my, I love it. Cool script, Bubs. You are one talented woman. I love your fortune cat avatar. Did you draw that one? You did a very good job on it.
Tue Jan 15th, 2008 1:27 pm
Robmarie (Quote, )
Bubs! The rotation is so shiny…. I can’t stop reloading the page! =P
Tue Jan 15th, 2008 4:40 pm
Chien Yee (Quote, )
Your avatars are so cute xD *refreshes non-stop*
Tue Jan 15th, 2008 4:55 pm
Rilla (Quote, )
There are some forums which do not recognise .php as a valid image location. It’d be helpful if you can change the code a bit so that you are able to access the rotation script with .jpg/gif/png.
Tue Jan 15th, 2008 5:14 pm
mendifae (Quote, )
very cool bubs!! I like your little example graphics too! You amaze me with your coding skills!
Tue Jan 15th, 2008 6:22 pm
Brent (Quote, )
Such a handy little script. I’ve use a variation of it before to display random photos before I discovered the magic that is Flickr <3 Thanks for sharing it though, it will come in handy
Wed Jan 16th, 2008 12:57 pm
Christine (Quote, )
Bubs. You are my hero. Seriously. I totally admire that you can just whip out a little script out of nothing!! I don’t currently troll any forums right now. but the moment I do, I’m so using this! <333
Wed Jan 16th, 2008 3:09 pm
Cherry (Quote, )
I remember using an avatar rotation script on a forum a while ago and I got so carried away with it that I had over 200 avatars in the rotation. Hehe
Thu Jan 17th, 2008 5:19 pm
Ashley (Quote, )
Very cute Bubs! I also refreshed many times to see all of the cuteness.
Fri Jan 18th, 2008 4:45 pm
Arwen (Quote, )
That’s really cool!
Sun Jan 20th, 2008 12:17 pm
Nanda (Quote, )
Wow, that looks pretty interesting! I’m sure a lot of people will find it handy and fun. But I have enough trouble finding or making one avatar for myself, so I’ll stick with one.
Tue Jan 22nd, 2008 11:00 am
Crystal (Quote, )
Sweet script! I wish I was as smart as you!
Sat Jan 26th, 2008 1:45 pm
FRutee (Quote, )
Nice script. haha.
I’ve been wondering how its done.
Tue Jan 29th, 2008 11:25 am
Shivon (Quote, )
That’s a really cool script, I wish I didn’t suck at keeping up with forums.
<3 Voni
Thu Jan 31st, 2008 1:31 am
Aisy (Quote, )
Hey there. I LOVE your theme. It’s very unique and neat! and cute too. and, how do you make your tabbed navigation work? I have tabs on my site but I couldn’t get them to work but I’ll get on that later when I’m sane enough. hehe…
and man, you’r so good with PHP.
Mon Feb 4th, 2008 10:52 am
Dhini (Quote, )
Cool script
Mon Aug 11th, 2008 12:16 pm
Farhana (Quote, )
Thanks for this script ^^
Fri Apr 16th, 2010 3:55 pm
Farhana replied to Farhana (Quote)
I don’t know if I’m the only person, but my .gif avatars aren’t animated for some reason when I use this script. I checked and they’re totally fine when I look at the direct link, animated avatars also work fine on my mb so I’m assuming it’s something to do with the script?
Fri Apr 16th, 2010 4:01 pm