Random Image Rotation from Folder of Images (PHP and JavaScript)

dmetzcher - December 24, 2008 - 04:16

Here is what I want to do...

I have a folder of images.
I want to use PHP to get that a list of all the images in that folder and put them into a JavaScript array.
I want JavaScript to rotate them, every few seconds, randomly.
I'd like a nice transition (I'd prefer fading from one image to another, or merging from one image to another...something like that.)

I do not want them to rotate only on page reload/refresh.

I have looked for several examples of this, but I'm either finding rotating images on page refresh, or random rotating image code (JavaScript) that requires me to enter the image filenames into the code itself. Once this is set up, I want to be able to change the images that are rotated by adding or removing images from the folder, without updating any code, so the examples I'm am finding are not quite what I need. The client needs to be able to add and remove images to/from the folder and will not be able to update code to make this work when I am gone.

Can someone please point me to the correct combination of code?

Thanks!

This looks interesting, but

dmetzcher - December 25, 2008 - 04:18

This looks interesting, but it doesn't grab the images from a directory...the users would have to create nodes every time a new image was added, or delete a node if they wanted to remove an image. They want to be able to just place images in a folder and have them appear in the rotation on the page.

I'm finding code that will randomly rotate an image on reload, using PHP, from a folder of images.
I'm also finding code that will randomly rotate an image using JavaScript, but it requires that every image filename be included in the code itself.

What I need is something that merges these two, and I'm not sure how to do it myself. I can't be the first one to want this, however.

Thanks for the link. That's something I'll keep in mind for other projects, but the client wants something specific with this one, so I have to go with something that can get files from a folder.

=-=

VM - December 25, 2008 - 04:21

It seems to me that one could use a scipt in a page content type with the php filter?

An interesting article on the subject = http://www.alistapart.com/articles/randomizer/

That was something I looked

dmetzcher - December 26, 2008 - 06:54

That was something I looked at as well. The only problem is that it doesn't use JavaScript, so the PHP code can only rotate the image(s) randomly when the page is reloaded.

Something like this, that rotates images randomly using nothing more than a folder of images as input, combined with some JavaScript that could rotate them every 3 seconds or so, without a page reload, is what I'm looking for.

I ended up going this route

dmetzcher - December 31, 2008 - 00:42

I ended up going this route and making a case for it with the client.
The person responsible for approving the design of the site likes the block I created, so I'm happy.

Thanks for all the suggestions, everyone. I'm bookmarking this page to keep everything close for future use.

have you seen the

WorldFallz - December 26, 2008 - 09:11

have you seen the http://drupal.org/project/brilliant_gallery module?

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

One of the planned features

dmetzcher - December 28, 2008 - 06:50

One of the planned features for Brilliant Gallery is "Option to show galleries as slideshows". I would probably need that feature now, since I want to have a single image displayed at any given time, randomly chosen from a folder of images.

The client would prefer something that is not managed via Drupal. They only want to add images to and remove them from a folder to control which images are displayed.

If this is going to be accomplished with a Drupal module, it would basically have to do exactly what PHP/JavaScript code would do, so I'm not sure anyone has written a module, since anyone who has done what I need to do would probably have just written PHP code into a node. That's what I'm looking to do, but I'm just not finding the right snippet of code to get it done.

Nodes can be a better option.

jorgedec - December 28, 2008 - 13:43

I'm working on something similar. I originally thought about reading the images from a folder but I opted to use a node with an attached image. This lets me add caption information, date information or even some sort of check box to the node using CCK. Then the code can select which images to show depending on date or some check box. I also think that attaching images to a node is easier and safer than sending images directly to a folder.

There's a module that does

ktleow - December 28, 2008 - 14:01

There's a module that does exactly what you needed.
Read files from a specific directory and plays the images in JavaScript slideshow.

http://drupal.org/project/couloir_slideshow

-----
Drupal theming services, PSD to Drupal
http://kahthong.com

 
 

Drupal is a registered trademark of Dries Buytaert.