Web Help Please!

Messages
873
Edit My Images
No
Hi all, hopefully someone will be able to help.

I'm looking for a small web application or flash script that when inserted into a html website will either change a picture every few seconds or change to a different pic every time the page is visited or refreshed.

Any web geniuses out there that can give me a clue where to look. Something free would be best :D

Thanks in advance

Dan
 
Brilliant thanks Kipax :)

I've also just found a java script that changes the homepage image randomly each time the page is loaded which may be more suited to the low key nature of the site in question.
 
I use the4 following on my site, feel free to adapt it by substituting the number of pictures and the URL's, just insert into the head tags where you want it to appear.

mine is pretty image heavy laden so might take a few seconds to load, see it in action at www.gcsportsphotos.co.uk


<script>
// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000

// Duration of crossfade (seconds)
var crossFadeDuration = 6

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = 'http://www.gcsportsphotos.co.uk/images/slide1.jpg'
Pic[1] = 'http://www.gcsportsphotos.co.uk/images/slide2.jpg'
Pic[2] = 'http://www.gcsportsphotos.co.uk/images/slide3.jpg'
Pic[3] = 'http://www.gcsportsphotos.co.uk/images/slide4.jpg'
Pic[4] = 'http://www.gcsportsphotos.co.uk/images/slide5.jpg'
Pic[5] = 'http://www.gcsportsphotos.co.uk/images/slide6.jpg'
Pic[6] = 'http://www.gcsportsphotos.co.uk/images/slide7.jpg'
Pic[7] = 'http://www.gcsportsphotos.co.uk/images/slide8.jpg'
Pic[8] = 'http://www.gcsportsphotos.co.uk/images/slide9.jpg'
Pic[9] = 'http://www.gcsportsphotos.co.uk/images/slide10.jpg'
Pic[10] = 'http://www.gcsportsphotos.co.uk/images/slide11.jpg'
Pic[11] = 'http://www.gcsportsphotos.co.uk/images/slide12.jpg'
Pic[12] = 'http://www.gcsportsphotos.co.uk/images/slide13.jpg'
Pic[13] = 'http://www.gcsportsphotos.co.uk/images/slide14.jpg'
Pic[14] = 'http://www.gcsportsphotos.co.uk/images/slide15.jpg'
Pic[15] = 'http://www.gcsportsphotos.co.uk/images/slide16.jpg'
Pic[16] = 'http://www.gcsportsphotos.co.uk/images/slide17.jpg'
Pic[17] = 'http://www.gcsportsphotos.co.uk/images/slide18.jpg'
Pic[18] = 'http://www.gcsportsphotos.co.uk/images/slide19.jpg'
Pic[19] = 'http://www.gcsportsphotos.co.uk/images/slide20.jpg'
Pic[20] = 'http://www.gcsportsphotos.co.uk/images/slide21.jpg'
Pic[21] = 'http://www.gcsportsphotos.co.uk/images/slide22.jpg'
Pic[22] = 'http://www.gcsportsphotos.co.uk/images/slide23.jpg'
Pic[23] = 'http://www.gcsportsphotos.co.uk/images/slide24.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad = new Image()
preLoad.src = Pic
}

function runSlideShow(){
if (document.all){
document.images.SlideShow.style.filter="blendTrans(duration=2)"
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
document.images.SlideShow.filters.blendTrans.Apply()
}
document.images.SlideShow.src = preLoad[j].src
if (document.all){
document.images.SlideShow.filters.blendTrans.Play()
}
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)
}
</script>
 
^^^ nice effect - fades don't work in Firefox - otherwise pretty good.
 
REALLY BASIC PHP script to change the image every time the site is refreshed:

PHP:
<?php
$dir = "images/"; //change to the images directory
$ext = ".jpg"; //change to file extension
$count = count(glob($dir.'*')) -1;
$i = rand(1, $count);

echo "<img src=\"".$dir.$i.$ext."\" alt=\"\" />";
?>

That's tested, and it works, but for some reason the count/glob combination is giving me 1 extra file on my server, so I reduced the total by 1 to keep it working properly. Change commented variables in the above code, and it will work for you :)

Let me know if you need any help.
 
REALLY BASIC PHP script to change the image every time the site is refreshed:

PHP:
<?php
$dir = "images/"; //change to the images directory
$ext = ".jpg"; //change to file extension
$count = count(glob($dir.'*')) -1;
$i = rand(1, $count);

echo "<img src=\"".$dir.$i.$ext."\" alt=\"\" />";
?>

That's tested, and it works, but for some reason the count/glob combination is giving me 1 extra file on my server, so I reduced the total by 1 to keep it working properly. Change commented variables in the above code, and it will work for you :)

Let me know if you need any help.

0 is a valid number and i dont think thats taken into consideration... when it gets $count as it will get number of files.. say 10... but the script should use 0-9

also i wouldnt use that script as it means reloading the pictures all the time instead of preloading them and using...
 
0 is a valid number and i dont think thats taken into consideration... when it gets $count as it will get number of files.. say 10... but the script should use 0-9

also i wouldnt use that script as it means reloading the pictures all the time instead of preloading them and using...
The script gets the number of files in a directory, then uses that to calculate a random. I should have said to name all files 1.jpg, 2.jpg etc. 0 isn't important in this case as the script works fine without taking it into consideration.

Yeah, preloading is an issue with this, but I assume this is used for a small-ish image which wouldn't really need preloading.
 
Have you tried setting $count = 0; beforehand?

Kipax - only the first time the page/script is ran you will encounter a bit of loading, once the images are cached it will run alot quicker and easier next time the page/script is loaded with the same images.

The javascript posted above is quite a bit and i wouldnt rely on that 100% for random images. Base on the randomness with php, and the effect with javascript. That way, users without javascript can still see the pretty pictures.

:)
 
Have you tried setting $count = 0; beforehand?

Kipax - only the first time the page/script is ran you will encounter a bit of loading, once the images are cached it will run alot quicker and easier next time the page/script is loaded with the same images.

The javascript posted above is quite a bit and i wouldnt rely on that 100% for random images. Base on the randomness with php, and the effect with javascript. That way, users without javascript can still see the pretty pictures.

:)
Surely $count would have a value of 0 to start with?

Just tested - no help. Thanks for the suggestion anyway.
 
Back
Top