Results 1 to 6 of 6

Thread: Load and Sort Images in a Slideshow from a folder

  1. #1
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Load and Sort Images in a Slideshow from a folder

    1) Script Title:
    Simple Controls Gallery

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...plegallery.htm

    3) Describe problem:
    I created a getpics.php file using the information on the previous forum post at http://www.dynamicdrive.com/forums/s...83&postcount=6 and integrated it into the slideshow script Simple Controls Gallery to have it load images from a folder on the server and create an array based upon those images.

    Currently, the getpics.php file loads and presents images randomly and I need help modifying it so that images are sorted, placed into the array, and presented (in the slideshow) in alphanumeric order (e.g. img001.jpg, img002.jpg, img003.jpg, etc...). Is this possible?

    This is the contents of the getpics.php file:
    Code:
    <?php
    Header("content-type: application/x-javascript");
    
    function returnimages($dirname="./images/") {
       $pattern="\.(jpg|jpeg|png|gif|bmp)$";
       $files = array();
       $curimage=0;
       if($handle = opendir($dirname)) {
           while(false !== ($file = readdir($handle))){
                   if(eregi($pattern, $file)){
                     echo 'galleryarray[' . $curimage .']=["' . $dirname . $file . '"];' . "\n";
                     $curimage++;
                   }
           }
    
           closedir($handle);
       }
       return($files);
    }
    
    echo "var galleryarray=new Array();" . "\n";
    returnimages();
    ?>
    I appreciate any assistance with this.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It would need almost a complete rewrite. But you can sort the images via javascript quite easily. If you're using Simple Gallery and this getpics.php file, you probably have something like so (highlighted line):

    Code:
    var mygallery=new simpleGallery({
    	wrapperid: "simplegallery1", //ID of main gallery container,
    	dimensions: [250, 180], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
    	imagearray: galleryarray,
    	autoplay: [true, 2500, 2], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
    	persist: false, //remember last viewed slide and recall within same session?
    	fadeduration: 500, //transition duration (milliseconds)
    	oninit:function(){ //event that fires when gallery has initialized/ ready to run
    		//Keyword "this": references current gallery instance (ie: try this.navigate("play/pause"))
    	},
    	onslide:function(curslide, i){ //event that fires after each slide is shown
    		//Keyword "this": references current gallery instance
    		//curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
    		//i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
    	}
    })
    in place of the manually typed out imagearray. If so, all you need to do is add a javascript sort:

    Code:
    var mygallery=new simpleGallery({
    	wrapperid: "simplegallery1", //ID of main gallery container,
    	dimensions: [250, 180], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
    	imagearray: galleryarray.sort(),
    	autoplay: [true, 2500, 2], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
    	persist: false, //remember last viewed slide and recall within same session?
    	fadeduration: 500, //transition duration (milliseconds)
    	oninit:function(){ //event that fires when gallery has initialized/ ready to run
    		//Keyword "this": references current gallery instance (ie: try this.navigate("play/pause"))
    	},
    	onslide:function(curslide, i){ //event that fires after each slide is shown
    		//Keyword "this": references current gallery instance
    		//curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
    		//i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
    	}
    })
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    idesign64 (06-04-2011)

  4. #3
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    It works great - Thanks for the help!

  5. #4
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    IS there a way that you would share the script you came up with that sorts the images for getpics.php? Been trying to implement all the things I've read on here and no go, just one simple thing for sorting webcam files so they end up in a nice row in the selection window by the date of the file. Right now it just grabs all the images at random and nothing is sorted in any manner. Much thanks - Jerris

  6. #5
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Are you using the Simple Controls Gallery script, as the person who originally started this thread is using?

    If so, the solution has been provided - just add sort() to the image array as John indicates in his reply above.

    If you are not using the Simple Controls Gallery script then please start a new thread for your question, clearly stating which script(s) you are using (you can refer back to this post with a link if you need to) with a description of your problem and a link to your web page.

    Please refer to this thread for the correct posting format: http://www.dynamicdrive.com/forums/showthread.php?t=6]
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by jerris77 View Post
    IS there a way that you would share the script you came up with that sorts the images for getpics.php? Been trying to implement all the things I've read on here and no go, just one simple thing for sorting webcam files so they end up in a nice row in the selection window by the date of the file. Right now it just grabs all the images at random and nothing is sorted in any manner. Much thanks - Jerris
    .sort() needs no script. It's native to all browsers.

    If you want more help, please start a new thread.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •