Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Feb 2005
    Location
    Near salt water
    Posts
    23,754
    Post Thanks / Like

    How do I create a rotating signature image?

    I get asked this all the time, and since I just pm'd someone a whole bunch of detail (again) on how to do this I thought I'd make up a thread instead.

    First of all, whats this about? My signature image changes every 30 minutes. At present I have something like 143 of them.

    What do you need to do it yourself? Well, its not for everyone. I am a programmer and I have access to web servers, where I can post files, run programs and most importantly schedule programs to run at repeated intervals.

    I'll run thru two ways to do it. Well, maybe three. All three will use ColdFusion as the application language. The code is easy to read so if you don't have access to a CF-enabled web server you can read whats here and convert it to PHP or .NET or whatever.

    The cornerstone of the whole thing is my signature is told to display a file named http://lelandwest.com/auto-tech/magnum/sigs/lxsig.jpg. The fact that your signature can display an image sitting on another server is what makes this all possible. You tell your sig to look for a file, and then you change that file on your side of the fence with the tools you have available.

    So here is the simplest version of the code. Basically in this example I have 31 sig files. they are named 1.jpg, 2.jpg, 3.jpg and so on up to 31.jpg. The code below will randomly pick one of the 31 available file names and copy that file to lxsig.jpg.

    PHP Code:
    <cfscript>
    variables.folderPath="c:/foo/bar/blah/blah/sigs/";
    variables.todayFile=variables.folderPath DatePart('d',now()) &  ".jpg";
    </
    cfscript>
    <
    cffile
        action
    ="copy"
        
    source="#variables.todayFile#"
        
    destination="#variables.folderPath#lxsig.jpg"
    This is very simple but its far from perfect. Assuming we run our sig changer once per day you get the same image on each day of the month. Image #31 will only be seen once every couple of months. Thats not particularly engaging.

    You can take a slightly different approach. Lets say I have the 143 files that I have now and I want to figure out a way to use code like whats above to use them. Here's what I could do: Pick a random image from the list of 143 files:

    PHP Code:
    <cfscript>
    variables.folderPath="c:/foo/bar/blah/blah/sigs/";
    variables.todayFile=variables.folderPath randRange(1,143) &  ".jpg";
    </
    cfscript>
    <
    cffile
        action
    ="copy"
        
    source="#variables.todayFile#"
        
    destination="#variables.folderPath#lxsig.jpg"
    That gives you access to more than 31 files, but if you don't know it already, you will quickly learn that "random" does not mean "evenly distributed". Sometimes images will show up repeatedly. Many images will show up rarely. Also you have to name the files with numbers, which is kind of a PITA. What you want is to walk thru your list of images and rotate them right down the line, one after the other.

    At one time I built such a thing and it ran completely in memory. All of the image names were housed in a persistent two-dimensional array and each image name had a flag element that was used to read in one image after another instead of dealing with random weirdness. The trouble with it was that, even though it was nicely self-contained, another word for a 2d array is 'database table' and it makes sense to use the right tool for the job. Moving the images to a for-reals database also allows me to write almost all of the code in SQL, which is a universal language that will make it easier for you reading this to customize into your own programming language.

    Since this is an application that I, a programmer am going to maintain I can take a couple of shortcuts since I don't have to worry about stuff like noobies having to be able to use my code. I'll describe those, but first here is the table spec. This is a mySQL db spec:

    PHP Code:
    CREATE TABLE `sigfiles` (
      `
    IDint(11NOT NULL,
      `
    filenamevarchar(255) default NULL,
      `
    isCurrentchar(1) default NULL,
      
    PRIMARY KEY  (`ID`),
      
    KEY `isCurrent` (`isCurrent`)
    ENGINE=MyISAM DEFAULT CHARSET=utf8 
    Note that the ID field is NOT an auto-increment field (thats an Identity field if you are using SQL Server). You will manually enter the ID number when you create each record, ensuring there are no gaps in your numbering sequence. The filename field holds your image name, without the path. For example: 'myimage.jpg'. Lastly, the value in the isCurrent field defaults to 0 (thats the number zero). Yes you could use a binary field and no I don't and I won't explain why :-)

    So you enter in all of your sig files into this table using the gui of your choice, or you write SQL to do it if you are a masochist. This is the code that walks thru the sigs. Almost everything is SQL here except for a few lines of code. One line of code in here needs to be updated by you, the genius programmer: The value in variables.sigs.lastID. If you want to get fancy you can do something like

    SELECT COUNT(ID) FROM sigfiles

    and plug that number in. On the version I use I actually do this. But thats a needless extra hit on the database. Just write in the record count.

    The code below has comments in it marked off with either <!--- and ---> or beginning with // on a line.

    PHP Code:
    <!--- 
    pull the current signature
    --->
    <
    cfquery 
        username
    ="#request.global.dbUN#"
        
    password="#request.global.dbPwd#" 
        
    name="getCurrent" 
        
    datasource="#request.global.dsn#">
        
    SELECT    
            sigfiles
    .ID
        FROM    
            sigfiles
        WHERE    
            sigfiles
    .isCurrent='1'
        
    ORDER BY
            sigfiles
    .ID ASC
    </cfquery>
    <
    cfscript>
    // set the base path 
    variables.sigs.folderPath="c:/foo/bar/yoo/hoo/magnum/sigs/";
    // List how many sigs I have in the database 
    variables.sigs.lastID=143;
    // default output to the first sig in the recordset
    variables.sigs.newCurrent=1;
    // now figure out if the current record is the last record in the recordset 
    if (getCurrent.ID is not variables.sigs.lastID) {
        
    // no its not the last one.  increment the current picture ID 
        
    variables.sigs.newCurrent=getCurrent.ID+1;
    }    
    </
    cfscript>
    <!--- 
    reset what was once the current signature --->
    <
    cfquery 
        username
    ="#request.global.dbUN#"
        
    password="#request.global.dbPwd#" 
        
    datasource="#request.global.dsn#">
        
    UPDATE sigfiles
        SET 
            sigfiles
    .isCurrent='0'
        
    WHERE 
            sigfiles
    .ID=#getCurrent.ID#
    </cfquery>
    <!--- 
    update to the new current sig --->
    <
    cfquery 
        username
    ="#request.global.dbUN#"
        
    password="#request.global.dbPwd#" 
        
    datasource="#request.global.dsn#">
        
    UPDATE sigfiles
        SET 
            sigfiles
    .isCurrent='1'
        
    WHERE 
            sigfiles
    .ID=#variables.sigs.newCurrent#
    </cfquery>
    <!--- 
    pull the filename of the new current file ... --->
    <
    cfquery 
        username
    ="#request.global.dbUN#"
        
    password="#request.global.dbPwd#" 
        
    name="getName" 
        
    datasource="#request.global.dsn#">
        
    SELECT    
            sigfiles
    .filename
        FROM    
            sigfiles
        WHERE    
            sigfiles
    .ID=#variables.sigs.newCurrent#
    </cfquery>
    <!--- ... and use 
    that filename to physically make a new default sig file. --->
    <
    cffile
        action
    ="copy"
        
    source="#variables.sigs.folderPath##getName.filename#"
        
    destination="#variables.sigs.folderPath#lxsig.jpg"
    Even thought the code windows above say 'PHP Code' thats just something the VBulletin software inserts. Its really ColdFusion. Also I did not use some essential best practices like cfqueryparam, to make the SQL easy for everyone to read. If you are using ColdFusion, use cfqueryparam or die.

    So THAT is how you make rotating signature images.
    Last edited by MattRobertson; 04-14-2010 at 10:11 PM.
    "LxF welcomes with open arms all members, regardless of social status, creed, color, sexual preference, or anything else. The only thing we discriminate against is douchebags."

    Check out Darth Hemi in the LxForums Garage



  2. #2
    MAN WGN's Avatar
    MAN WGN is offline Livin in the worlds biggest Dust Bowl!!
    Join Date
    Jul 2008
    Location
    Midland, TX
    Posts
    742
    Post Thanks / Like
    WOW, thanks for that now I feel even more stupid than before.
    2005 MAN WAGON

  3. #3
    Join Date
    Oct 2005
    Location
    Mississippi
    Posts
    4,209
    Post Thanks / Like
    you lost me at coldfusion, lol

    I look forward to seeing what your sig is everytime i see one of your posts.. always a treat!

  4. #4
    HULK's Avatar
    HULK is offline West Coast Style Meets East Coast Power


    Join Date
    Aug 2007
    Location
    Chicago, IL
    Posts
    7,979
    Post Thanks / Like
    Me no speaky techy....





    OK, maybe I speak it a little bit.... but not that much, lol. Some day I shall be on your level, oh great one.

    Quote Originally Posted by Simans82 View Post
    Compared to your modding addiction, I'm just looking at the coke on the table. You on the other hand, you're more like Scarface.

  5. #5
    Join Date
    Jan 2006
    Posts
    1,749
    Post Thanks / Like
    Very nice....another option is to have a random image selected for each hit real-time:


    ==== perl code snippet for 143 images named 1.gif to 143.gif ====
    #!/usr/local/bin/perl
    print "Content-Type: image/gif\n\n";

    my $random=int(rand(144));
    my $randomSig="c:/foo/bar/yoo/hoo/magnum/sigs/$random.gif";

    open (IMAGE, "<$randomSig");
    while ( <IMAGE> ) {
    print $_;
    }
    ==== end of code ====

    A few more lines of code and you could give it the folder name and let it get all the file names and then select randomly among them. This would not require a running job or cron job to swap the files- random new one every time.

    Note: untested, but should work with something close.
    Enjoy life- you only get one!!

  6. #6
    Join Date
    May 2004
    Location
    Bakersfield (yes, Bakersfield)
    Posts
    5,151
    Post Thanks / Like
    No flux capaciter with that? I guess I'll just stick to animated gifs. I know - sooooo 2 years ago.

    (Waiting "patiently" for the 300C SRT8 8-speed) Coming.....soon?

  7. #7
    Join Date
    Nov 2005
    Location
    New York
    Posts
    11,587
    Post Thanks / Like
    eeeeeyyaaaAAA...... ummm Matt, like how many keyboards do you go through in a month?.... 'cause like, mine last for yeeeeeears doooooood.....mmmm'kay.
    RIP

    12.869 @ 102.02 Stock 5.7 w/ C&L, Predator, JBA Cats, Volant catback, 3.06 Getrag, DRs & skinnies www.hemirace.com

  8. #8
    Join Date
    Feb 2005
    Location
    Near salt water
    Posts
    23,754
    Post Thanks / Like
    Quote Originally Posted by Shelby View Post
    Very nice....another option is to have a random image selected for each hit real-time
    Thats an interesting idea. How does perl interject itself into the mix when calling a .gif file from an outside source?

    If I could do this in VB:

    Code:
    [img]http:\\foohbar.com\arf\arf\imageflipper.cfm[/img]
    In other words, link an image to a .cfm file instead of a .gif or a .jpg - then I could serve up an image like what you're doing. But the CF processor only handles certain file extensions.

    In perl wouldn't I have to do this:

    Code:
    [img]http:\\foohbar.com\arf\arf\imageflipper.cgi[/img]
    in my signature window?

  9. #9
    Join Date
    Feb 2005
    Location
    Near salt water
    Posts
    23,754
    Post Thanks / Like
    Quote Originally Posted by MattRobertson View Post

    If I could do this in VB:

    Code:
    [img]http:\\foohbar.com\arf\arf\imageflipper.cfm[/img]
    Well I'll be damned (probably am, anyway). You *can* do that. My sig is running like that right now. Still calls the same image. Just in a different way. Could have sworn that VB didn't allow images with nonstandard extensions.

    To write shelby's idea in Coldfusion it would look like this:

    PHP Code:
    <cfcontent 
        file
    ="c:/foo/bar/blah/blah/sigs/#randRange(1,143)#.jpg" 
        
    type="image/jpeg" 
        
    deletefile="No"
    This will serve up an image randomly every single time. It won't do the nice neat even progression of images, which you might find to be an issue, but its quick and dirty and works just dandy.


    edit: For all the CF stuff, you have to know your server's physical path to the files from root. Not the url... the path. Tech geeks will know what this means.
    Last edited by MattRobertson; 04-15-2010 at 12:15 AM.

  10. #10
    Join Date
    Jan 2006
    Posts
    1,749
    Post Thanks / Like
    Quote Originally Posted by MattRobertson View Post
    Thats an interesting idea. How does perl interject itself into the mix when calling a .gif file from an outside source?

    If I could do this in VB:

    Code:
    [img]http:\\foohbar.com\arf\arf\imageflipper.cfm[/img]
    In other words, link an image to a .cfm file instead of a .gif or a .jpg - then I could serve up an image like what you're doing. But the CF processor only handles certain file extensions.

    In perl wouldn't I have to do this:

    Code:
    [img]http:\\foohbar.com\arf\arf\imageflipper.cgi[/img]
    in my signature window?
    Correct.....glad you like it!

  11. #11
    Join Date
    Mar 2006
    Location
    Phoenix, AZ
    Posts
    19,224
    Post Thanks / Like
    Ooof. My head hurts now.


    FB: www.facebook.com/chargerchick
    Twitter & Instagram: @chargerchick412

    AZLX Facebook page: https://www.facebook.com/groups/240409256167396/

  12. #12
    Join Date
    Feb 2005
    Location
    Near salt water
    Posts
    23,754
    Post Thanks / Like
    There will be a quiz later so I hope you took notes :D

    ...

    So. We have a few examples in ColdFusion and one in Perl. Who wants to write something in PHP or .NET? If anyone's interested post it up here.

  13. #13
    Join Date
    Oct 2005
    Location
    Riverside, Ca
    Posts
    20,455
    Post Thanks / Like
    Dooooood, you REALLY need to get a girl friend.
    From wild to extra wild we got you covered with crap ya never knew you needed.





    The first 6.1 transformation and it all went down hill from there.

    08 route 66 burnout champion 07 Shindig 6.1NA winner. Willow Springs 1:42!!. 11.796 @ 117mph


  14. #14
    Join Date
    Feb 2008
    Location
    Oshawa Ontario
    Posts
    6,069
    Post Thanks / Like
    Hmm interesting.. may have to look at doing up some sigs vs. just the text soon..

    Have IIS7, php, MSSQL, MySQL and about anything else I wanna install available.
    2006 Lil Red Wagon SXT
    Modlist : AFE Stage II, JBA Headers, Corsa Catback, 20" Vipers, Cross Drilled Rotors, Diablo Bob@SVS Tuned, Pioneer DEH-5000UB, 12" Enclosers, Halos, Low/Fog HIDs, Cuda Grille, TruFiber Chally Hood.

    at the Track

    My Garage


    Mentoria Computer Consulting

  15. #15
    Join Date
    Jan 2006
    Posts
    1,749
    Post Thanks / Like
    You could obviously do the Super-Geek:

    Random real-time images delivered via script with animated images (either cool animations or a few rotating ones)

Page 1 of 2 12 LastLast

Share This Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •