Good random image script

software development



I am looking for a good random image generator and haven’t had much luck with google. The problem is that integrating any sort of script into my website is very new to me, with the exception of running Greymatter for my photolog (yeah, I know, I don’t have to actually touch code).

I have a place on the front page set aside for an image and a folder full of images of the same dimentions. Now I just need something to tie the two together. I want a different image displayed everytime the page is loaded, but not a slideshow or anything else too heavy.

A mockup of the page will be at if it ever finishing uploading.The big rectangle below the top banner is where the image will be placed. I’ve placed a clear gif over it as a link to the gallery page.

Thanks in advance for any suggestions/links/snippets


This script uses random number filenames. Filename would be name 0.jpg, 1.jpg, 2.jpg, etc.


[/code]I added a space between < and ! and -- and > otherwise everything inbetween does not show in this forum. Silk


You didn’t really indicate if you have any coding experience. The impression I have is that you don’t have much.

What generates your home page? A script? Or is it a static page?

If it’s PHP, you can use this simple, inefficient random image Frankenscript. (I chopped out some of my site-specific info, but this ought to do the job.)

No specific file-naming conventions and no need to change the script as new images are added. But it is inefficient.


<? $count = 0; function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } /* Define current dir */ $current_dir = 'images/dirname'; $RAND_MAX = mt_getrandmax(); mt_srand(make_seed()); /* Open current local dir for reading */ $cd_handle = opendir($current_dir); /* While we find files and dirs in the current dir... */ while (($file = readdir($cd_handle)) !== false) { /* Check for dot files, so we don't use .htaccess and ./.. dirs */ if (substr($file, 0, 1) != '.' && $file !='index.php') { $count++; $filearray[$count] = $file; } } /* Close the open dir */ closedir($cd_handle); $rand = mt_rand(); $randval = intval( ( $rand / $RAND_MAX ) * $count ); $file = $filearray[ $randval ]; print ''; ?>


The Origional Poster actauly posted this question in another place after not getting any reponses here for a day or so.