since people want to know how, here's a script you can use for a random sig. simply save the file as sig.php on your server:<?php
header("Content-Type: image/jpeg"); $sigs = array(); // reference your sig images here $sigs[] = "http://url.com/sig1.jpg"; $sigs[] = "http://url.com/sig2.jpg"; $sigs[] = "http://url.com/sig3.jpg"; mt_srand((double)microtime()*1000000); $sig = $sigs[mt_rand(0, count($sigs)-1)]; $im = ImageCreatefromjpeg("$sig"); Imagejpeg ($im);
?>then to use it, put the following (minus the spaces in the bbcode for img) in your sig:
[ img ]http://url.com/path/to/sig.php [ /img ]
Here's a version for lazy people like me -- it finds all images with the 'sig-' prefix in a given directory (including gifs if your PHP serer supports them) and chooses one at random. So you just drop the image into the directory and it'll be recognised automatically. It also creates a warning image if an error occurs.
Looks complicated but it's not, really -- you use it exactly like mosquito's code, above. You can change the prefix if you need to, as well.
[php] <?php
// Set variables $image_dir = './'; $image_prefix = 'sig-'; $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()
?> [/php]
:notworthy
More fun - want to use this same code as a header on your site? Make a pile of headers the same size as your normal header cell in your page, and save them to a seperate directory on your site. Now, save the php our helpful friends have provided as header.php ...
Now, instead of writing out your header, just call it from a div like so :
and in your css, add this:
header {
background: (header.php) no-repeat;
}
You can still have text in your header, this just defines your background... easy as pie.
Im wondering if it makes the different in speed and load if I use $fp = fopen($path, "rb"); fpassthru($fp); Just simply read the file the push it out. Because as long as you dont modify the output image, i dont see the need to use ImageCreatefromjpeg()
try it out and let us know. I'd be grateful for the feedback if you tried it out.
I tried it out, didnt notice ant difference (I should have calculated the load speed by milisec, but I didnt). The good thing is: using fpassthru your animated gif files still work, while ImageCreatefromgif() will stop them from working. Of course there are many ways to make animated gif files work with mageCreatefromgif() but they are kinda complicated.
Another thing: using fpassthru you simply read the file and push it out so you can still hide the real path to the files (assuming you want to), and dont really care about the file types (png, bmp, jpg, gif,... all work), you may want to restrict the file types users can use tho.
thanks for the feedback :thumbsup:
By the way, welcome aboard :beer:
ari should be along shortly with barrel duty, etc...
You can also write a mini function to handle text signature: draw a blank image then draw the text on it. Example:http://www.shareparadise.net/rotate/1.gif
Refresh a few times you should see some text signatures image (created by php) PS: Great thanx to mosquito & Stickman for the tut, you gave me great inspiration.
HOwdy and welcome aboard! Friday is your turn in the barrel. :beer: