The purpose of this code is to easily display a large number of images by rotating through them, one at a time.
The script must be installed into a .php page, or your server must be set up to process PHP code within the file extension you wish to use.
The PHP script outputs a combination of HTML and JavaScript and provides easy access to several vaiables that can be used to change the
presentation of the slideshow.
Options allow you to change:
Copy your .JPG, .JPEG or .GIF images into one or more directories on your web server. Think of each directory of images as a slideshow. Copy the code into your web page, then set up the code to include the directories you've created and set up the various options. If you have set up the options to display the controls, viewers of your page may select which slideshow to watch, whether the image files are presented sequentially or randomly and the delay time between picture.
Here's an example of this code in action
\n";
}
/*
Only show the pick list of slideshows if it is needed.
*/
if ( ($mycount > 1) && $show_picklist ) {
echo 'Pick a Topic: ';
echo '\n";
echo "
\n";
echo "
\n";
}
/*
Only show the Random option if it is needed.
*/
if ( $show_random == true ) {
echo " Shuffle the Pictures?\n";
echo "
\n";
echo "
\n";
}
/*
Only display the the control to adjust the delay if needed.
*/
if ( $delay < 1000 ) { // Less than 1 second
$delay_time = "1.0";
} elseif ( $delay < 10000 ) { // Less than 10 seconds
$delay_time = number_format($delay/1000, 1);
} elseif ( $delay < 100000 ) { // Less than 100 seconds
$delay_time = number_format($delay/1000, 0);
} else { // 100 seconds or more
$delay_time = 100;
}
if ( $show_delay == true ) {
/*
The spinner is inspired by stuff found at www.webcodingtech.com.
*/
echo "\n";
echo "
\n";
echo "\n";
echo " \n";
echo "Delay Time between Pictures: \n";
echo "\n";
echo " \n";
echo " seconds \n";
echo "\n";
echo " ";
echo "\n";
echo "
\n";
echo "
\n";
} else { // Don't show the delay box, but still put up an invisible one
echo "\n";
}
}
function funWritePicLine1( $directory, $blnUsePicSize, $pic_height, $pic_width, &$n, &$arrWidth, &$arrHeight, $label, &$arrLabelsForEachPicture )
{
if ($directory == "" ) $directory = ".";
$image_handle = opendir(getcwd() . "/" . $directory);
while (false !== ($filename = readdir($image_handle))) {
$image_files[] = $filename;
}
sort($image_files);
foreach ( $image_files as $image_file ) {
$arrLabelsForEachPicture[$n] = $label;
if ( ($image_file != ".") && ($image_file != "..") ) {
if ( strpos(strtolower($image_file), '.gif', 1) || strpos(strtolower($image_file), '.jpg', 1) || strpos(strtolower($image_file), '.jpeg', 1) ) {
if ( $blnUsePicSize == "false" ) {
// Get the dimensions of the image within the file.
list($image_width, $image_height) = getimagesize($directory . "/" . $image_file);
$ratioh = $pic_height/$image_height;
$ratiow = $pic_width/$image_width;
$ratio = min($ratioh, $ratiow);
// New dimensions
$arrWidth[$n] = intval($ratio * $image_width);
$arrHeight[$n] = intval($ratio * $image_height);
echo " pic" . $n . "= new Image(" . $arrWidth[$n] . ", " . $arrHeight[$n] . ");";
} else {
echo " pic" . $n . "= new Image(0, 0);";
}
echo ' pic' . $n . '.src="' . $directory . "/" . $image_file . '";';
echo "\n";
$n++;
}
}
}
}
function put_label($location, $strLabel)
{
if ($location != "")
$strPosition = strtolower( substr($location, 1, 1) );
switch ($strPosition) {
case "":
echo "document.write(\"\\n\");\n";
break;
case "l":
echo "document.write(\"
So, did we really need to get fancy and use two different programming languages for this?
Yes, we did and the reason is pretty straigtforward.
JavaScript is just what we need to update the pictures every few seconds, creating the 'sllideshow' effect.
However, JavaScript can't do things like 'list' the files within directories or get at each image's height and width
After building many slideshows in the past where I typed in the name of every single file I'm using, I decided that it was time
to start using PHP to do these kinds of tasks.
In the process, we have a tool that's easy and flexible to use.