TwelvestoneFAQ

random sig script


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
mosquito
 
2003-10-03

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 ]

Stickman
 
2003-10-03

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]

Anti-Deity
 
2003-10-03

:notworthy

arigato
 
2004-03-06

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.

yellow1912
 
2006-05-27

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()

tenPlus
 
2006-05-28

try it out and let us know. I'd be grateful for the feedback if you tried it out.

yellow1912
 
2006-05-28

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.

tenPlus
 
2006-05-28

thanks for the feedback :thumbsup:

Stinky
 
2006-05-28

By the way, welcome aboard :beer:

ari should be along shortly with barrel duty, etc...

yellow1912
 
2006-05-31

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.

arigato
 
2006-05-31

HOwdy and welcome aboard! Friday is your turn in the barrel. :beer:

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFAQ

random sig script