PDA

View Full Version : Swiss Army control image presentation



stmosaic
05-09-2014, 12:59 AM
1) Script Title: Swiss Army Image Slideshow

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex14/swissarmy/index.htm

3) Describe problem: Love this script!! No so much a problem as wanting to upgrade the functionality. I was wondering if there is a way to control the presentation so that it will get images from a folder in reverse order.

I use this on a site where I am adding new images all the time and would love to be able to automate to go to that image folder grab the images in reverse order, so my newest images show first rather than either my older images first or having to renumber everything each time I add new photos. My images are labeled 001.jpg, 002.jpg, etc.

Is this possible? My javascript skills are limited, do have some php skills, but mostly with php4.

jscheuer1
05-09-2014, 01:45 AM
Grabbing images from a folder is more a job for PHP. And it's less of an issue which version of PHP you are familiar with than of which version is available to you on the server. This should work in PHP 4 or 5:


<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="swissarmy.js" type="text/javascript">

/***********************************************
* Swiss Army Image slide show script - John Davenport Scheuer: http://home.comcast.net/~jscheuer1/
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full original source code
***********************************************/

</script>
<script type="text/javascript">
<?php
function returnimages(){
$dirname = './pics_bak/'; //relative path to image folder
$pattern = '#\.(jpg|jpeg|png|gif|bmp)$#i';
$files = array();
if($handle = opendir($dirname)){
while(($file = readdir($handle)) !== false){
if(preg_match($pattern, $file)){
array_push($files, "\t['" . $dirname . $file . "', '', '']");
}
}
closedir($handle);
natsort($files);
}
return "inter_slide.slides = [\n" . implode(",\n", $files) . "\n];\n";
}

echo returnimages();
?>

inter_slide.slides.reverse(); // reverse the order of the array of images

var preload_ctrl_images=false; //if true, set paths to the control images

//Optional Options for the slideshow:
inter_slide.slides.no_descriptions=1; //use for no descriptions displayed
inter_slide.slides.pause=1; //use for pause onmouseover
inter_slide.slides.fadecolor='#111'; //will set fading images background color, defaults to white
</script>
</head>
<body>
<script type="text/javascript">
new inter_slide(inter_slide.slides, 800, 650)
</script>
</body>
</html>

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

stmosaic
05-09-2014, 06:54 PM
John, Thank you, that was exactly what I needed! And so elegant to boot!!

jscheuer1
05-10-2014, 05:22 AM
Um, great!

I just noticed though that I have natsort($files); in there. That takes the array of files and sorts them alpha-numerically as a human would. But I think you said you wanted the actual order in the folder. If so, comment out that line.