Dynamic Image Rotation

15 Apr

<script language=”php”>
// =============================================================
// Script: Image Rotation Script
// With Adjustable Timing and Unlimited Images
// Utilizes META REFRESH
// Function: Displays random images continuously in a slideshow
// presentation format
// PHP ver: 3.x, 4.x
// Author: Jarrod Major
// Email: jarrod@nucleus.com
// Copyright: (C)2001 Nucleus Information Service Inc.
// Licence: Free, drop me a line letting me know where you
// used the script. Please keep this header attached.
// =============================================================
// Disclaimer:
// Use of this code is at the programmer’s own risk. Damage
// to any property as a result of the script’s use is the sole
// responsibility of the programmer, no blame shall be laid on
// the author of this script or his employer.
// =============================================================

function rotate_images()
{
// open directory, images must be in a separate directory
$dir_pointer = dir( “pic” );

// make an array of filenames
while( $entryName = $dir_pointer->read() )
{
// don’t include parent/current directory listing /. /..
if( !ereg( “^\.”, $entryName ) )
$file_array[] = $entryName;

// could be done this way to simplify some code below
# $file_array[] = “directory_name/$entryName”;
}

// close directory
$dir_pointer->close();

$count_array = count( $file_array ) – 1;

// intialize random seed
srand( time() );

// get a random index number to pull from array
$random_no = rand( 0, $count_array );

// make a file pointer
$file_name = “directory_name/$file_array[$random_no]”;

// or if directory added to array element
#$file_name = $file_array[$random_no];

// get image dimensions
$image_size = getimagesize( $file_name );

// create dynamic image tag
$out = sprintf( ‘<img src=”%s” %s alt=”image.” />%s’, $file_name, $image_size[3], “\n” );

return $out;
}
</script>
<html>
<head>
<!– to adjust timing change ‘content’ value below –>
<meta http-equiv=”Refresh” content=”3″ />
<title>Test Image shuffler</title>
</head>
<body>
<?php print rotate_images(); ?>
</body>
</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: