Randomizing forum signatures.

Results 1 to 12 of 12
  1. #1
    Alpha Member Justei is offline
    MemberRank
    Oct 2007 Join Date
    /f241Location
    1,904Posts

    Randomizing forum signatures.

    Well, I was having a hard time picking a signature for my profile, then I thought, why not use all of them instead?

    So, I present to you: My random signature ... thingie.

    lol basically what it does is that it randomizes my signatures every time someone refreshes and displays a different one :).

    (Example is in my signature).

    If you want one then hit me up and I might make one for ya if I have some time over :), if a lot of people want this I might just make it an automated service (it's pretty easy so).


    Here's the source code if anyone is interested, it's coded like crap since well, I made this script in what, 2 hours, parts of it are not written by me and parts are, (the functions in the end arent by me.)

    The rest should be mine, not sure, old script lol.

    Anyhow, as you can see you also need a table with the following columns: id, sig_refresh.

    And that should be it lol.
    Spoiler:


    PHP Code:
    <?php    

    $link 
    mysql_connect('ip''user''pw');
    if (!
    $link) {
         die(
    'Could not connect to DATABASE: ' mysql_error());
    }
    mysql_select_db(''$link);

    /*
    Coded by Justei (Kristoffer Blasiak)
    For: RaGEZONE.com
    */

    $q2 mysql_query("UPDATE signature_fun SET sig_refresh = sig_refresh + 1 WHERE id = '1'")or die(mysql_error());
        
    $q mysql_query("SELECT * FROM signature_fun WHERE id = '1'")or die(mysql_error());
    $r mysql_fetch_row($q);

        
    $text 'Justei random sigs ftw ^^'

        if(empty(
    $text))
            
    fatal_error('Error: Text not properly formatted.') ;


        
    // customizable variables
        
    $font_file     "ambient.ttf";
        
    $font_size      22 // font size in pts
        
    $font_size2     11 ;
        
    $i rand(17);
        
        if(
    $i == 1){
            
    $font_color     '#ffffff';
            
    $font_color2     '#ffffff' ;
        }
        
        if(
    $i == 2){
            
    $font_color     '#000000';
            
    $font_color2     '#000000' ;
        }
        
        if(
    $i == 3){
            
    $font_color     '#000000';
            
    $font_color2     '#000000' ;
        }
        
        if(
    $i == 4){
            
    $font_color     '#ffffff';
            
    $font_color2     '#ffffff' ;
        }
        
        if(
    $i == 5){
            
    $font_color     '#ffffff';
            
    $font_color2     '#ffffff' ;
        }
        
        if(
    $i == 6){
            
    $font_color     '#ffffff';
            
    $font_color2     '#ffffff' ;
        }
        
        if(
    $i == 7){
            
    $font_color     '#ffffff';
            
    $font_color2     '#ffffff' ;
        }
        
        
    $image_file     'img/'.$i.'.png';

            

        
    // x and y for the bottom right of the text
        // so it expands like right aligned text
        
    $x_finalpos     200;
        
    $y_finalpos     30;
        

        
        
    // trust me for now...in PNG out PNG
        
    $mime_type             'image/png' ;
        
    $extension             '.png' ;
        
    $s_end_buffer_size     4096 ;



        
    // check for GD support
        
    if(!function_exists('ImageCreate'))
            
    fatal_error('Error: Server does not support PHP image generation') ;

        
    // check font availability;
        
    if(!is_readable($font_file)) {
            
    fatal_error('Error: The server is missing the specified font.') ;
        }

        
    // create and measure the text
        
    $font_rgb hex_to_rgb($font_color) ;
        
    $font_rgb2 hex_to_rgb($font_color2) ;
        
    $box = @ImageTTFBBox($font_size,0,$font_file,$text) ;

        
    $text_width abs($box[2]-$box[0]);
        
    $text_height abs($box[5]-$box[3]);
        

        
    $image =  imagecreatefrompng($image_file);

        if(!
    $image || !$box)
        {
            
    fatal_error('Error: The server could not create this image.') ;
        }

        
    // allocate colors and measure final text position
        
    $font_color ImageColorAllocate($image,$font_rgb['red'],$font_rgb['green'],$font_rgb['blue']) ;
        
    $font_color2 ImageColorAllocate($image,$font_rgb2['red'],$font_rgb2['green'],$font_rgb2['blue']) ;

        
    $image_width imagesx($image);

        
    $put_text_x $image_width $text_width - ($image_width $x_finalpos);
        
    $put_text_y $y_finalpos;
        
        
    // Write the text
        
    $put_text_y2 $y_finalpos 18;
        
    $put_text_y3 $y_finalpos 40;
        
        
    $text2 $r[1].' views of my sig ^^!';
        
    $text3 'Coded by: Justei @ RageZone.com';
        
        
    imagettftext($image$font_size010,  $put_text_y$font_color$font_file$text);
        
    imagettftext($image$font_size2010,  $put_text_y2$font_color2$font_file$text2);
        
    imagettftext($image$font_size2010,  $put_text_y3$font_color2$font_file$text3);
        

        
    header('Content-type: ' $mime_type) ;
        
    ImagePNG($image) ;

        
    ImageDestroy($image) ;
        exit ;


        function 
    fatal_error($message)
        {

            
    // send an image
            
    if(function_exists('ImageCreate'))
            {
                
    $width ImageFontWidth(5) * strlen($message) + 10 ;
                
    $height ImageFontHeight(5) + 10 ;
                
                if(
    $image ImageCreate($width,$height))
                {
                    
    $background ImageColorAllocate($image,255,255,255) ;

                    
    $text_color ImageColorAllocate($image,0,0,0) ;
                    
    ImageString($image,5,5,5,$message,$text_color) ;    

                    
    header('Content-type: image/png') ;
                    
    ImagePNG($image) ;
                    
    ImageDestroy($image) ;
                    exit ;
                }
            }

            
    // send 500 code
            
    header("HTTP/1.0 500 Internal Server Error") ;
            print(
    $message) ;
            exit ;

        }
        
        
    /* 
            decode an HTML hex-code into an array of R,G, and B values.
            accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff 
        */    

        
    function hex_to_rgb($hex) {

            
    // remove '#'

            
    if(substr($hex,0,1) == '#')

                
    $hex substr($hex,1) ;

        

            
    // expand short form ('fff') color to long form ('ffffff')

            
    if(strlen($hex) == 3) {

                
    $hex substr($hex,0,1) . substr($hex,0,1) .

                       
    substr($hex,1,1) . substr($hex,1,1) .

                       
    substr($hex,2,1) . substr($hex,2,1) ;

            }

        

            if(
    strlen($hex) != 6)

                
    fatal_error('Error: Invalid color "'.$hex.'"') ;

        

            
    // convert from hexidecimal number systems

            
    $rgb['red'] = hexdec(substr($hex,0,2)) ;

            
    $rgb['green'] = hexdec(substr($hex,2,2)) ;

            
    $rgb['blue'] = hexdec(substr($hex,4,2)) ;

        

            return 
    $rgb ;

        }

    ?>


    Add from alphakilo23:
    Add:
    PHP Code:
    imagealphablending($imagetrue);
    imagesavealpha($imagetrue); 
    after declaring the $image variable.
    Last edited by Justei; 11-08-11 at 07:40 PM.


  2. #2
    Canadian Mike is offline
    MemberRank
    Dec 2007 Join Date
    Toronto, ONLocation
    2,747Posts

    Re: Randomizing forum signatures.

    Very nice script, but how exactly do you use it on forums? I thought PHP and HTML was blocked?

  3. #3
    Banned Yamachi is offline
    BannedRank
    Oct 2006 Join Date
    Jolly EnglandLocation
    3,517Posts

    Re: Randomizing forum signatures.

    @Mike: You use a simple Rewrite rule to change requests for the PNG/JPG to the PHP file, and the PHP file takes care of outputting the expected data stream (ie. an image).

    I have something similar to this called "SigBawx" that a friend wrote. It allows people to submit messages that are displayed in someone else's signature, along with their name (like a chat box). I might fix it up and release the source here.

  4. #4
    Alpha Member Justei is offline
    MemberRank
    Oct 2007 Join Date
    /f241Location
    1,904Posts

    Re: Randomizing forum signatures.

    Quote Originally Posted by Yamachi View Post
    @Mike: You use a simple Rewrite rule to change requests for the PNG/JPG to the PHP file, and the PHP file takes care of outputting the expected data stream (ie. an image).

    I have something similar to this called "SigBawx" that a friend wrote. It allows people to submit messages that are displayed in someone else's signature, along with their name (like a chat box). I might fix it up and release the source here.
    Well, I don't really do it that way above, check out the php script, then I just do a <img src="link-to-my.php"/>

    I host that in a .php file, then just use that to link in the src="" of a <img :P

    Obviously I don't use the <img tag, but u can embed pics here in your sigs, so I just input my link there :)
    Last edited by Justei; 11-08-11 at 02:44 PM.

  5. #5
    Account Upgraded | Title Enabled! Alphakilo23 is offline
    MemberRank
    Jun 2010 Join Date
    Ze German ländLocation
    428Posts

    Re: Randomizing forum signatures.

    It replaces the PNG transparency with black, is there a workaround for that?
    Disregard that, I suck at googling, here's the fix:

    Add:
    PHP Code:
    imagealphablending($imagetrue);
    imagesavealpha($imagetrue); 
    after declaring the $image variable.

    Source: PHP: imagecreatefrompng - Manual
    Last edited by Alphakilo23; 11-08-11 at 07:34 PM.

  6. #6
    Alpha Member Justei is offline
    MemberRank
    Oct 2007 Join Date
    /f241Location
    1,904Posts

    Re: Randomizing forum signatures.

    Quote Originally Posted by Alphakilo23 View Post
    It replaces the PNG transparency with black, is there a workaround for that?
    Disregard that, I suck at googling, here's the fix:

    Add:
    PHP Code:
    imagealphablending($imagetrue);
    imagesavealpha($imagetrue); 
    after declaring the $image variable.

    Source: PHP: imagecreatefrompng - Manual
    Added to first post :) didn't need alpha channel so didn't even care about it ^^ but useful for some people!

  7. #7
    Infraction Baɴɴed holthelper is offline
    MemberRank
    Apr 2008 Join Date
    1,765Posts

    Re: Randomizing forum signatures.

    question?

    is this your first attempt at the GD library?

    EDIT:
    sorry couldnt resist
    PHP Code:
    <?php
    /*
    Coded by Justei (Kristoffer Blasiak)
    EDITED BY: Holthelper
    For: RaGEZONE.com
    */

    // trust me for now...in PNG out PNG
    $mime_type IMAGETYPE_PNG;

    // customizable variables
    $font_file  "ambient.ttf";
    $font_size  22 ;
    $font_size2 11 ;
    $image_inc  rand(17);
    $image_src 'img/'.$image_inc.'.png';

    // x and y for the bottom right of the text
    $x_pos 200;
    $y_pos 30;

    if(!
    $image = @imagecreatefrompng($image_src)) {
        
    fatal_error('Error: The server could not create this image.') ;
    }

    if(!
    $link mysql_connect('localhost''root''')) {
        die(
    'Could not connect to DATABASE: ' mysql_error());
    }
    mysql_select_db(''$link);

    function 
    fatal_error($message) {
        
    // send an image
        
    if(function_exists('ImageCreate')) {
            
    $width ImageFontWidth(5) * strlen($message) + 10 ;
            if(
    $image ImageCreate($width25)) {
                
    $background ImageColorAllocate($image,255,255,255) ;
                
    $text_color ImageColorAllocate($image,0,0,0);
                
    ImageString($image,5,5,5,$message,$text_color);    

                
    header('Content-type: image/png');
                
    ImagePNG($image);
                
    ImageDestroy($image);
                exit;
            }
        }
        
    header("HTTP/1.0 500 Internal Server Error") ;
        print(
    $message) ;
        exit;
    }

    function 
    hex_to_rgb($hex) {
        
    $rgb['red']   = hexdec(substr($hex,1,2));
        
    $rgb['green'] = hexdec(substr($hex,3,2));
        
    $rgb['blue']  = hexdec(substr($hex,5,2));
        return 
    $rgb;
    }


    mysql_query("UPDATE `signature_fun` SET `sig_refresh` = sig_refresh + 1 WHERE `id` = '1'") or die(mysql_error());
    $r mysql_fetch_row(mysql_query("SELECT `sig_refresh` FROM `signature_fun` WHERE `id` = '1'"));

    switch(
    $image_inc) {
        case 
    1:
        case 
    4:
        case 
    5:
        case 
    6:
        case 
    7:
            
    $font_color  '#ffffff';
        break;
        case 
    2:
        case 
    3:
            
    $font_color  '#000000';
        break;
    }

    // Text
    $title 'Justei random sigs ftw ^^';
    $view $r[0].' views of my sig ^^!';
    $cred 'Coded by: Justei @ RageZone.com';

    // Text Color
    $RGB hex_to_rgb($font_color);

    // check font availability;
    if(!is_readable($font_file)) {
        
    fatal_error('Error: The server is missing the specified font.') ;
    }

    // allocate colors and measure final text position
    $font_color ImageColorAllocate($image$RGB['red'], $RGB['green'], $RGB['blue']) ;

    imagettftext($image$font_size,  010,  $y_pos$font_color$font_file$title);
    imagettftext($image$font_size2010,  $y_pos 18$font_color$font_file$view);
    imagettftext($image$font_size2010,  $y_pos 40$font_color$font_file$cred);

    header('Content-type: '.Image_Type_To_Mime_Type($mime_type));
    ImagePNG($image);
    ImageDestroy($image);
    ?>
    SQL:
    Code:
    DROP TABLE IF EXISTS `signature_fun`;
    CREATE TABLE  `signature_fun` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `sig_refresh` int(13) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    Last edited by holthelper; 12-08-11 at 10:23 PM.

  8. #8
    Alpha Member Justei is offline
    MemberRank
    Oct 2007 Join Date
    /f241Location
    1,904Posts

    Re: Randomizing forum signatures.

    Holthelper: well I never needed it before so never had to use it :p so yes this is the first time i use it, I know its messy, thats cus i took this directly from another project I had made :) made it in like 2h so :p

    And, so basically what you did was reorganize my code, clean it up, and made a switch case, okay. Anyhow.
    Last edited by Justei; 13-08-11 at 01:07 PM.

  9. #9
    Banned Yamachi is offline
    BannedRank
    Oct 2006 Join Date
    Jolly EnglandLocation
    3,517Posts

    Re: Randomizing forum signatures.

    @hotlhelper: Instead of coming here, asking if this is the first time someone has used a certain library before (that is a blatant underlying insult), then posting modified code and claiming that you "couldn't resist" (pretty smug, don't you think?), how about you point things out and GENUINELY try to help, without acting like you're better and trying to insinuate that Justei is somehow of lesser intelligence?

  10. #10
    Infraction Baɴɴed holthelper is offline
    MemberRank
    Apr 2008 Join Date
    1,765Posts

    Re: Randomizing forum signatures.

    im not insulting him at all, i know he can code better then that. so when i saw this messy code i had to clean it.

    idk about you but i have sorta OCD so it just bugged the sh*t out of me that it was really messy and redundant.

    ive been messing with the GD library from some time now as you can tell from my sig

  11. #11
    █║▌║▌║TheMerc iful║▌║▌║█ 4pLay is offline
    MemberRank
    Jan 2005 Join Date
    DXBLocation
    1,444Posts

    Re: Randomizing forum signatures.

    Damn! Yamachi!!!

    I Just Saw Your Siggy... And Boy Do i LOL'd Too Much!!!

    Sorry, For The Off Topic! But Thanks For This Randmizing Sig. That i Just Saw...

  12. #12
    • ♠️​ ♦️ ♣️ ​♥️ • שเ๒єtгเ๒є is offline
    MemberRank
    Mar 2012 Join Date
    917Posts

    Re: Randomizing forum signatures.

    oh Justei, there is one problem, users browser cache ~ :P
    (or do browser detect its a script and force reloading everytime? ._o)



Advertisement