Jump to content
xisto Community
karlo

Simple Image Rotator randomly rotate images

Recommended Posts

First, It's really confusing. Do you know any tutorials on Image Manipulation on PHP?

 

Here's another simple one:

 

1. Create a 5 image.

2. Rename them to something like: image1.jpg; image2.jpg; and so on...

3. Create your PHP file (rotation.php)

4. Enter the following code:

 

<?phpheader("content-type: image/jpeg");readfile("image".mt_rand(1,3).".jpg");?>
5. Execute your script.

Share this post


Link to post
Share on other sites

You save the images in the directory as the rotation is in.

53798[/snapback]


Yes. Or you can change it... example "images/rotate/ads/image"

Share this post


Link to post
Share on other sites

Here's an even easier way, if that's too complicated. lol.

 

<? $show = 2; //change 5 to number of buttons you want to show $button[] = "|-img code here-|";$button[] = "|-img code here-|"; //and so on srand ((float) microtime() * 10000000); $Keys = array_rand($button, 3); //change 5 to number of buttons you want to show for($K = 0; $K < $show; $K++){ echo "".$button[$Keys[$K]].""; } ?>

Just add more lines of $button[] = "|-img code here-|"; to the code to make more images! Hope that helps! ;)

Share this post


Link to post
Share on other sites

Here's an even easier way, if that's too complicated. lol.

 

<? $show = 2; //change 5 to number of buttons you want to show $button[] = "|-img code here-|";$button[] = "|-img code here-|"; //and so on srand ((float) microtime() * 10000000); $Keys = array_rand($button, 3); //change 5 to number of buttons you want to show for($K = 0; $K < $show; $K++){ echo "".$button[$Keys[$K]].""; } ?>

Just add more lines of $button[] = "|-img code here-|"; to the code to make more images! Hope that helps! ;)

54119[/snapback]


It's more difficult! Especially in using Arrays! http://forums.xisto.com/topic/7711-confused-some-php-functions-that-i-am-confused/

Share this post


Link to post
Share on other sites

I got this image rotator:

<?php// Make this the relative path to the images, like "../img" or "random/images/".// If the images are in the same directory, leave it blank.$folder = 'fotos/banner/';// Space seperated list of extensions, you probably won't have to change this.$exts = 'jpg jpeg png gif';$files = array(); $i = -1; // Initialize some variablesif ('' == $folder) $folder = './';$handle = opendir($folder);$exts = explode(' ', $exts);while (false !== ($file = readdir($handle))) {    foreach($exts as $ext) { // for each extension check the extension        if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive            $files[] = $file; // it's good            ++$i;            }        }    }closedir($handle); // We're not using it anymoremt_srand((double)microtime()*1000000); // seed for PHP < 4.2$rand = mt_rand(0, $i); // $i was incremented as we went alongheader('Location: '.$folder.$files[$rand]); // Voila!?>

It's working but I wanted it to make a .jpg file not a .php so I could put it on a forum... do you guys know if I can do it?

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

×
×
  • 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.