Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: ShadowStriker - kesäkuu 17, 2007, 02:03:22 IP

Otsikko: Image Rotation?
Kirjoitti: ShadowStriker - kesäkuu 17, 2007, 02:03:22 IP
I have seen this before, but I don't know how they did it. I think they put a link to a folder (on the internet) or something with all their sigs in, and then every couple seconds (when you refresh) it switches sigs to a different one in that folder. How do you do this?
Otsikko: Re: Image Rotation?
Kirjoitti: Alan S - kesäkuu 17, 2007, 02:48:33 IP
Okay , heres how you do it.

Create a Php file named "random_image.php" with this code

<?php

// print a random image. Don't forget ending slash!
// setting $type to 'all' will return all images.

function getRandomImage($dir,$type='random')
{
global 
$errors,$seed;

if (
is_dir($dir)) {

$fd opendir($dir);
$images = array();

while ((
$part = @readdir($fd)) == true) {

if ( 
eregi("(gif|jpg|png|jpeg)$",$part) ) {
$images[] = $part;
}
}

// adding this in case you want to return the image array
if ($type == 'all') return $images;

if (
$seed !== true) {
mt_srand ((double) microtime() * 1000000);
$seed true;
}

$key mt_rand (0,sizeof($images)-1);

return 
$dir $images[$key];

} else {
$errors[] = $dir.' is not a directory';
return 
false;
}
}

?>



Create a folder on your site called something like "sigimages" and place it in there.

Then create another php file called "images.php" with this code

<?php
require_once("random_image.php");
$pic getRandomImage('path/to/images/');
?>



replace path/to/images/' with the path to the folder the images are in.

Place the "images.php" in the same folder as "random_image.php" and also place all your pictures in there.

Then in your bbc sig code use this code

[img]http://yoursite.com/sigimages/image.php[/img]


Obviously replace the  link to your image.php address.
Otsikko: Re: Image Rotation?
Kirjoitti: ShadowStriker - kesäkuu 17, 2007, 04:35:07 IP
Ok I did all that, but I get a broken image
Otsikko: Re: Image Rotation?
Kirjoitti: ShadowStriker - kesäkuu 19, 2007, 12:09:11 AP
bump
Otsikko: Re: Image Rotation?
Kirjoitti: Alan S - kesäkuu 19, 2007, 09:15:53 AP
Hmmm , Okay Give me a hour or so to get some personal stuff out of the way and then i'll look into it further.
Otsikko: Re: Image Rotation?
Kirjoitti: ShadowStriker - kesäkuu 21, 2007, 11:07:05 AP
bump
Otsikko: Re: Image Rotation?
Kirjoitti: Alan S - kesäkuu 21, 2007, 12:39:45 IP
Hmmm okay , I dont know what the problem is but a quick google search turned up this , Take a look

http://alistapart.com/articles/randomizer/
Otsikko: Re: Image Rotation?
Kirjoitti: Bulakbol - kesäkuu 29, 2007, 08:49:37 AP
Lainaus käyttäjältä: Alan S - kesäkuu 21, 2007, 12:39:45 IP
Hmmm okay , I dont know what the problem is but a quick google search turned up this , Take a look

http://alistapart.com/articles/randomizer/

Thanks. I got this thing working. It's great.  ;)