PDA

View Full Version : Image Rotation


iollo
06-16-2006, 11:27 AM
You can use this code snippet to rotate your images on your site. You can use it let's say for rotating images beside your adsense ads :D


<?php
$path_to_images = "images/"; // path to your images
$default_img = "turtle.gif"; // image to display if directory listing fails

function getRandomImage($path, $img) {
if ( $list = getImagesList($path) ) {
mt_srand( (double)microtime() * 1000000 );
$num = array_rand($list);
$img = $list[$num];
} return $path . $img;
}

function getImagesList($path) {
$ctr = 0;
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// can add checks for other image file types here
if ( preg_match("/(\.gif|\.jpg)$/", $img_file) ) {
$images[$ctr] = $img_file;
$ctr++;
}
}
closedir($img_dir);
return $images;
} return false;
}
?>


You can see sample on http://free-css-templates.com

seoguyz
07-16-2006, 07:45 PM
Hey thats pretty good mate! Did you think of it etc or did the people at http://free-css-templates.com do it?

Interesting... Could be used for a random background generator.. Got one of those though...

hmm..

well, rotation is always useful! :D Cheers dude!

Duality
07-16-2006, 10:53 PM
I've always seen this code but I might have a use for it now. Thanks!

Matto
07-17-2006, 12:05 PM
Cool little code snip there mate. Looks like it would be very useful.

ptucker
07-19-2006, 04:29 AM
yea, I agree, looks pretty cool, i've been creating my images in whatever layout I needed for the YPN in photoshop but this may work better.