corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Anyone fluent in PHP? » Post Reply

Post Reply
Who Can Post? All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help

Insert Bold text Insert Italicized text Insert Underlined text Insert Centered text Insert a Hyperlink Insert Email Hyperlink Insert an Image Insert Code Formatted text Insert Quoted text
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
Post Options: Disable smileys?
Turn BBCode off?
Receive email notification of new replies?

AndyKent

posted on 10th Dec 08 at 13:41

Or that, yes :)


Laney

posted on 10th Dec 08 at 13:37

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

posted on 10th Dec 08 at 13:13

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.


Bart

posted on 10th Dec 08 at 12:58

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. :(


colour_golden

posted on 10th Dec 08 at 12:46

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

posted on 10th Dec 08 at 08:56

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? :|