Jump to content
xisto Community
Sign in to follow this  
soleimanian

Coppermine Random Image Script

Recommended Posts

If you have the ability to use PHP, it is easy to make a random image script. Give each picture the same name but with a number at the end of it (make foo.bar foo1.bar footype.bar foo2.bar). Then stick the following code anywhere in the page and make sure the page is a .php type.(The instructions are in the comments).

<?php$min = 1; //The first number one of your images has$max = 10; //The highest number you image has$number = rand($min, $max);$url = "http://forums.xisto.com/no_longer_exists/; . $number . ".bar"; //change the url to your url //for the image split the url into two parts by separating in between the image name and //extensionecho "<img src='$url'>";?>

That ought to do it.

Share this post


Link to post
Share on other sites

Here, another way if you'd like to use javascript on your page.

The steps involved in randomly displaying an image from a set are very similar to those used for displaying random text strings.
1. Initializing an array
2. Storing the image file names in that array
3. Finding the length of this array
4. Using the Math.random() to generate a random number
5. Using the randomly generated number as index for retrieving an image file name from the array.
6. Displaying the image.

var img_name = new Array("purple.gif", "red.gif",
"blue.gif", "yellow.gif", "green.gif", "pink.gif");

var l = img_name.length;

var rnd_no = Math.round((l-1)*Math.random());

document.r_img.src = img_name[rnd_no];

<IMG SRC="blank.gif" WIDTH="100" HEIGHT="50"
NAME="r_img" ALT="Random image">


They are just a simple one, you could find a lot more on the net through Google.

This matter could also be done in Flash which is flashier but not really easy to do. Tutorial of how to do it can be found through search engines too. Check out http://www.flashkit.com/ if you are serious to Flash.

Share this post


Link to post
Share on other sites

If you want to use php instead of javascript (and I'm not saying either's better), but want the javascript ability to have totally different names, you can use this code:

<?php$location = "http://blah.blah.foo/foobar"; //this should be the folder containing the //images if they are in separate folders, ignore this line and make the full location of the //images the replacement for pic#.ext in the next line$pictures = ("pic1.ext", "pic2.ext", "pic3.ext"); //make pic#.ext the name of one of your //images no rules as to format of the name this time$maxnum = count($pictures);$randnum = rand(0, maxnum-1);echo "<img src='$pictures[$randnum]'>";?>

Share this post


Link to post
Share on other sites

i want do the randomly change image without the random() function so how can i do

Coppermine Random Image Script

 

 

This is my code . So I want the code which will work without random function.

Share this post


Link to post
Share on other sites

i want the code without random() function.

Coppermine Random Image Script

 

I m using this code for randomly change the image .

 

 

 

 

 

 

-question by Ravi Jadaun

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.