Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


How to Make a Rotating Image filter_list
Author
Message
How to Make a Rotating Image #1
This PHP script will randomly select an image file from a folder of images on your webserver. You can then link to it as you would any standard image file and you'll see a random image each time you reload.

When you want to add or remove images from the rotation-pool, just add or remove them from the image rotation folder. There is no need to edit the original file every time you add a new image.

____________________________


Instructions

1. Copy and paste the code below into a txt file. Rename the file to be 'index.php'.

2. Create a folder on your webserver called 'rotate.jpeg'.

3. Upload the file (index.php) to your rotate.jpeg folder.

4. Upload all the images you want to be in the cycle into that same folder.

5. Link to the file as you would any normal image file, like this:

<img src="http://example.com/rotate.jpeg">
or on a web forum
{img}http://example.com/rotate.jpeg{/img}

You can also specify the image to display like this:

<img src="http://example.com/rotate.php?img=gorilla.jpg">

This would specify that an image named "gorilla.jpg" located
in the image-rotation folder should be displayed.

That's all, enjoy.

____________________________


Code

PHP Code:
<?php


    $folder 
'.';


    
$extList = array();
    
$extList['gif'] = 'image/gif';
    
$extList['jpg'] = 'image/jpeg';
    
$extList['jpeg'] = 'image/jpeg';
    
$extList['png'] = 'image/png';
    

$img null;

if (
substr($folder,-1) != '/') {
    
$folder $folder.'/';
}

if (isset(
$_GET['img'])) {
    
$imageInfo pathinfo($_GET['img']);
    if (
        isset( 
$extListstrtolower$imageInfo['extension'] ) ] ) &&
        
file_exists$folder.$imageInfo['basename'] )
    ) {
        
$img $folder.$imageInfo['basename'];
    }
} else {
    
$fileList = array();
    
$handle opendir($folder);
    while ( 
false !== ( $file readdir($handle) ) ) {
        
$file_info pathinfo($file);
        if (
            isset( 
$extListstrtolower$file_info['extension'] ) ] )
        ) {
            
$fileList[] = $file;
        }
    }
    
closedir($handle);

    if (
count($fileList) > 0) {
        
$imageNumber time() % count($fileList);
        
$img $folder.$fileList[$imageNumber];
    }
}

if (
$img!=null) {
    
$imageInfo pathinfo($img);
    
$contentType 'Content-type: '.$extList$imageInfo['extension'] ];
    
header ($contentType);
    
readfile($img);
} else {
    if ( 
function_exists('imagecreate') ) {
        
header ("Content-type: image/png");
        
$im = @imagecreate (100100)
            or die (
"Cannot initialize new GD image stream");
        
$background_color imagecolorallocate ($im255255255);
        
$text_color imagecolorallocate ($im0,0,0);
        
imagestring ($im255,  "IMAGE ERROR"$text_color);
        
imagepng ($im);
        
imagedestroy($im);
    }
}

?>
[Image: iOgmBiXM3rChO.gif]

Reply

RE: How to Make a Rotating Image #2
Cool, I made an avatar one
[Image: UGAvatar.jpeg]
(This post was last modified: 04-27-2013, 08:51 PM by Dismas.)
[Image: eAwhVeW.png]

Reply

RE: How to Make a Rotating Image #3
Damn, this is really cool. Nice tutorial, Ocean.
:fuckyea:

Reply

RE: How to Make a Rotating Image #4
If you mean like a slideshow from this then you can do it in js too.

Reply







Users browsing this thread: 1 Guest(s)