Image Rotate script

Discussion in 'PHP' started by heyman12, Oct 19, 2008.

  1. #1
    I am looking for a good script to rotate an image with a static URL to change every time you refresh the page. This is for a signature system btw.

    
    
    <img src="http://domain.com/img1.jpg />
    
    
    Code (markup):
    So the file img1.jpg will have a new image associated with it. I do not want the HTML to change at all, just that the actuall file is governed by a Php script.

    I heard somewhere there is a way to have the the image file a .php file... is there a way to do this?
     
    heyman12, Oct 19, 2008 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    make a folder named img1.jpg
    place images in it

    put an index.php file in it:

    <?php
    $pictures = array("picture.jpg","picture2.jpg","picture3.jpg");
    header("Content-type: image/jpg");
    echo file_get_contents($pictures[rand(0,(count($pictures)-1))]);
    ?>

    there
     
    Kyosys, Oct 19, 2008 IP
  3. Conello

    Conello Member

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #3
    a simple php script for your code
    <img src="http://yourdomain.com/images/rotate<?php echo(rand(1,5)); ?>.jpg" />

    make sure, you have file with named:
    rotate1.jpg
    rotate2.jpg
    rotate3.jpg
    rotate4.jpg
    rotate5.jpg

    I think you'll get the idea :D
     
    Conello, Oct 19, 2008 IP
  4. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    He said he wanted an image with a static url to rotate
     
    Kyosys, Oct 20, 2008 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    There's a lot of ways to do it.
    What your ideal way of managing which images are used in the rotation is a big factor in which one would be best for you.

    I would try to get Apache & mod_rewrite to do as much of the leg work as possible, but that might just be me.
    For instance if I had 10 images in a "signatures" folder I might use something like this in my htaccess to rewrite requests to "sig.jpg" to one of the 10 sigs named "0.jpg" through "9.jpg" using a 302 Temporary redirect so the browser will keep checking and getting redirected.

    
    RewriteEngine On
    
    RewriteCond %{TIME_SEC} ([1-9])$
    RewriteRule sig\.jpg$ signatures/%1.jpg [R=302,L]
    
    Code (markup):
     
    joebert, Oct 20, 2008 IP