Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 17

6apxatCurtisOdenHotBlackericgillettelf349141590 +12 guests

Random Image/ Slideshow

Hey, I was wondering if anyone could lend a hand. I am after a php (or javascript. not sure what will work best) script to randomly display an image from a directory. I would also like the image to change every x seconds. So that would be a BIG PLUS! Re-sizing would, again be a plus, but really not so big an issue, so this comes later on. If anyone HAS or KNOWS OF a script that does this, if you could share this information with me it would be great. Any help is much appreciated.

Comments

  • Posts: 893
    Here is some javascript I found I think could be used. What I need now is a way to have it select from a directory, and not from specific, pre specified files. ---------------------------------------------- var images = new Array(); images[0] = "image1.gif"; images[1] = "image2.gif"; images[2] = "image3.gif"; function ShowImg() { var number = images.length; var increment = Math.floor(Math.random() * number); var strTemp ='<img src="' + images[increment] + '">'; document.write(strTemp); } var rotate = 5000; var count = 0; function RotateImg(myImage){ myImage.src=images[count]; count++; if(count==images.length){count = 0;} setTimeout("RotateImg(myImage)",rotate); } ----------------------------------------------
  • Posts: 5,574
    Um. I *think* I could write this in php. The idea doesnt seem too hard. Remind me when i get home.
  • Posts: 893
    How do I know when you get home? *reminds anyway*
  • Posts: 5,574
    that will have been about right. unfortunately for the first evening in months i didnt check vanilla till i'm off again. Keep bumping.
  • Posts: 893
    *bumps *
  • Posts: 893
    are you home yet?
  • Posts: 893
    mini?
  • Posts: 5,574
    hi. i was just thinking about this. then i stopped. I'll get onto it now.
  • Posts: 893
    cheers. I really appreciate it.
  • to do it with php, you'd have to reload the document - not sure if this is the effect you'd be after.
  • Posts: 893
    no. not realy, I would rather them just sort of 'roll on by' in a slide show. So, the image changes every 5 seconds for example.
  • yeah - js or flash. flash would be more graceful.
  • Posts: 893
    I dislike flash.
  • Posts: 5,574
    meh. here's roughly what i think youre talking about in php anyway since i've done it. http://badassg.me.uk/randomimage.php The source is there under .phps if anyone wants to take it and have a play around or even use bits of it along with javascript. (n.b. it refreshes 1 of 2 images because there are only 2 in the directory not cuz its broke.) If you want any of the source explaining (its really pretty simple if you've used php before) i'll be around for the next 10 otherwise i'm sure someone else can give you a hand.
  • Posts: 893
    wow. thanks mini. No explanation needed. (I know you are not here anyway). Now... Is anyone up for some JS integration? I would like ot have this WHITHIN another page, so I think this on its own won't/ can't refresh an image ONLY (not the whole page). Any takers?
  • Posts: 5,574
    as a thought you could stick that in a frame (i didnt put resizing on but i/someone could if it'd help) and just have it refresh that frame. JS would probably be much better but i'm afraid i've never used it.
  • Posts: 893
    That would be great as a temporary measure. I am working on JS version, but I must say, I am not very good at it. Thanks for your help mini.
  • Posts: 5,574
    no probs. If you know how to do the transition with JS you could always use my php to do the image selection...if that helps atall?
  • Posts: 893
    it does. thanks
  • Posts: 5,574
    chuck a post up when you're done. I'll be interested to see how you've got it working. I made a slideshow type thing for my friend a while ago just to flick her through all the pics in a directory (i do think it'd be a nice ability for the filebrowser but i suppose its not really a core feature. I still think it should be extensionised) but that was in order and in a similar fashion to the one above. Transitions or whatever to make it smoother would be nice.
  • Posts: 893
    it would, but as I said, my knowledge is limited, but there are heaps of js transitions available that don't seem to hard to implement.
  • Posts: 893
    I have done it. (finally).

    Here is the source.

    It loads all the images into the js array when the page loads, then the js randomly displays an image and rotates them every x seconds (2 by default).

    This script (in its current form) can only be run if the IMAGES are in a directory UNDER this script.

    Sorry for the delay. Enjoy.
  • Posts: 893
    alright. it is not working. everytime I post it, it does not work. I'll put it on my sites forum and post a link here. If anyone wants it, drop me a line and I will send it to you.
  • Posts: 893
    Linky: http://skoap.com/node/28 Thanks to anyone that help. I used none of your code, or suggestions, but I appreciate the offer :P
  • Posts: 1,010
    I'll have to give this a whirl :)

    Thanks.
  • Posts: 1,433

    Sweet... this might answer my question about adding random thumbnails to each folder in Filebrowser

This discussion has been closed.