Bart
Member
Registered: 19th Aug 02
Location: Midsomer Norton, Bristol Avon
User status: Offline
|
im trying to randomly rotate 4 images on my website. Ive found a script that will randomly rotate a single image, but not more than one.
If I copy the code multiple times it shows the same 4 images. Ive created a number of php files and called upon a different php file for each image, but still no different.
The code ive found is:
quote:
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
// You don't need to edit anything after this point.
// --------------------- END CONFIGURATION -----------------------
$img = null;
if (substr($folder,-1) != '/') {
$folder = $folder.'/';
}
if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
file_exists( $folder.$imageInfo['basename'] )
) {
$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
}
}
if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
}
}
?>
Does anyone know how to modify the above to suit?
|
colour_golden
Member
Registered: 24th Feb 08
Location: Hull - UK
User status: Offline
|
doesnt make sense, how do you rotate one image?
Unless you mean rotate as in landscape to Portrait or do you mean rotate as in slideshow type rotate?
[Edited on 10-12-2008 by colour_golden]
|
Bart
Member
Registered: 19th Aug 02
Location: Midsomer Norton, Bristol Avon
User status: Offline
|
randomly rotate, as in, it shows one image, you click refresh and it shows another image.
It does work, but when using it more than once it shows all for of the same images.
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
I'd chuck all that code in the bin and start over.
Save your images as index1, index2, index3, index4 (for example).
Then generate a random integer between 1 & 4 with $ran_num = rand(1,4);
Then code the path to the image;
$image = 'index'.$ran_num.'.jpg';
Then just get the code to insert $image whereever its required on the page.
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by aPk
I'd chuck all that code in the bin and start over.
Save your images as index1, index2, index3, index4 (for example).
Then generate a random integer between 1 & 4 with $ran_num = rand(1,4);
Then code the path to the image;
$image = 'index'.$ran_num.'.jpg';
Then just get the code to insert $image whereever its required on the page.
...or
$image='index'.rand(1,4).'.jpg';
if you're wanting to paste the same code and generate different images each time
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
Or that, yes
|