The Answer...

Trojan

Respected Member
Joined
Jun 15, 2004
Messages
3,545
Reaction score
2
Location
OG From '02
The answer to every noob and guru's question of 'How do I get my signature to go all random like?'.

Just copy and paste this code into notepad and change the line that says "enter prefix here" to whatever you want and make every image you want to include in the rotation have the same prefix such as, trojan1, trojan2, trojan3 etc... After that save it as a .php file and upload that and the images in the same folder and paste the .php location on your host to the forums in tags. I hope I answered a bunch of people's questions.

[code]<?php



// Set variables

$image_dir = './';

$image_prefix = 'enter prefix here';

$imageArray = array();



// Set image types

if(function_exists("imagegif")){

$image_types = array( 'gif', 'jpg' );

} else {

$image_types = array( 'jpg' );

}



// Get all sig images

$dir = dir( $image_dir );

while ( false !== ( $image_name = $dir->read() ) ) {



$image_info = pathinfo( $image_name );

// If it's an iamge and it starts with the correct prefix

if( in_array( @$image_info[ 'extension' ], $image_types ) && substr( $image_name, 0, strlen( $image_prefix ) ) == $image_prefix ){

array_push( $imageArray, array( 'name' => $image_name, 'type'=> $image_info['extension'] ) );

}



}

$dir->close();



// Did it find any?

if( count($imageArray) ){



// Yes

// Choose a random one

$image = $imageArray[ rand( 0, count( $imageArray )-1 ) ];



switch( $image[ 'type' ] ){



// Create a gif image

case('gif'):{

if($load_image = @ImageCreatefromgif( $image_dir . $image[ 'name' ] )){

header("Content-Type: image/gif");

Imagegif($load_image);

} else {

createErrorImage( 'Error creating gif' );

}

break;

}



// Create a jpeg image

case('jpg'):{

if($load_image = @ImageCreatefromjpeg( $image_dir . $image[ 'name' ] )){

header("Content-Type: image/jpeg");

Imagejpeg($load_image);

} else {

createErrorImage( 'Error creating jpeg' );

}

break;

}



} // END switch( $image[ 'type' ] )



} else {



// No

// Create an error image

createErrorImage( 'No images found' );



}



// Create an error image

function createErrorImage( $error ) {



$load_image = imagecreate (300, 50);

$background= imagecolorallocate ($load_image, 255, 255, 255);

$text_colour = imagecolorallocate ($load_image, 0, 0, 0);

imagefilledrectangle ($load_image, 0, 0, 150, 30, $background);

imagestring ($load_image, 1, 5, 5, "Error: $error", $text_colour);

header("Content-Type: image/jpeg");

Imagejpeg($load_image);



} // END function createErrorImage()



?>[/code]
 

NewPosts

New threads

Top