Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Image Rotator - Need Help with php or java code

    I have been looking for an image rotator that swaps images by date and time from my severs time set. Similar to what internet radio stations use for their DJs. I have yet to find the right one that works. Please forgive me for the example will be long.

    Example:

    Sun - 10 March 2009
    0000 - 0900 = "image/DJ-00.png"
    0900 - 1000 = "image/DJ-1.png"
    1000 - 1100 = "image/DJ-2.png"
    1100 - 1200 = "image/DJ-3.png"
    1200 - 1300 = "image/DJ-4.png"
    1300 - 1400 = "image/DJ-5.png"
    1400 - 1500 = "image/DJ-6.png"
    1500 - 1600 = "image/DJ-7.png"
    1600 - 1700 = "image/DJ-8.png"
    1700 - 1800 = "image/DJ-9.png"
    1800 - 1900 = "image/DJ-10.png"
    1900 - 2000 = "image/DJ-11.png"
    2000 - 2100 = "image/DJ-12.png"
    2100 - 0000 = "image/DJ-00.png"

    Mon - 11 March 2009
    0000 - 0900 = "image/DJ-00.png"
    0900 - 1000 = "image/DJ-13.png"
    1000 - 1100 = "image/DJ-14.png"
    1100 - 1200 = "image/DJ-15.png"
    1200 - 1300 = "image/DJ-16.png"
    1300 - 1400 = "image/DJ-17.png"
    1400 - 1500 = "image/DJ-18.png"
    1500 - 1600 = "image/DJ-19.png"
    1600 - 1700 = "image/DJ-20.png"
    1700 - 1800 = "image/DJ-21.png"
    1800 - 1900 = "image/DJ-22.png"
    1900 - 2000 = "image/DJ-23.png"
    2000 - 2100 = "image/DJ-24.png"
    2100 - 0000 = "image/DJ-25.png"

    Tue - 12 March 2009
    0000 - 0900 = "image/DJ-00.png"
    0900 - 1000 = "image/DJ-26.png"
    1000 - 1100 = "image/DJ-27.png"
    1100 - 1200 = "image/DJ-28.png"
    1200 - 1300 = "image/DJ-29.png"
    1300 - 1400 = "image/DJ-30.png"
    1400 - 1500 = "image/DJ-31.png"
    1500 - 1600 = "image/DJ-32.png"
    1600 - 1700 = "image/DJ-33.png"
    1700 - 1800 = "image/DJ-34.png"
    1800 - 1900 = "image/DJ-35.png"
    1900 - 2000 = "image/DJ-36.png"
    2000 - 2100 = "image/DJ-37.png"
    2100 - 0000 = "image/DJ-00.png"

    Wed - 13 March 2009
    0000 - 0900 = "image/DJ-00.png"
    0900 - 1000 = "image/DJ-38.png"
    1000 - 1100 = "image/DJ-39.png"
    1100 - 1200 = "image/DJ-40.png"
    1200 - 1300 = "image/DJ-41.png"
    1300 - 1400 = "image/DJ-42.png"
    1400 - 1500 = "image/DJ-43.png"
    1500 - 1600 = "image/DJ-44.png"
    1600 - 1700 = "image/DJ-45.png"
    1700 - 1800 = "image/DJ-46.png"
    1800 - 1900 = "image/DJ-47.png"
    1900 - 2000 = "image/DJ-48.png"
    2000 - 2100 = "image/DJ-49.png"
    2100 - 0000 = "image/DJ-00.png"

    Thur - 14 March 2009
    0000 - 0900 = "image/DJ-00.png"
    0900 - 1000 = "image/DJ-50.png"
    1000 - 1100 = "image/DJ-51.png"
    1100 - 1200 = "image/DJ-52.png"
    1200 - 1300 = "image/DJ-53.png"
    1300 - 1400 = "image/DJ-54.png"
    1400 - 1500 = "image/DJ-55.png"
    1500 - 1600 = "image/DJ-56.png"
    1600 - 1700 = "image/DJ-57.png"
    1700 - 1800 = "image/DJ-58png"
    1800 - 1900 = "image/DJ-59.png"
    1900 - 2000 = "image/DJ-60.png"
    2000 - 2100 = "image/DJ-61.png"
    2100 - 0000 = "image/DJ-00.png"

    Fri - 15 March 2009
    0000 - 0900 = "image/DJ-00.png"
    0900 - 1000 = "image/DJ-62.png"
    1000 - 1100 = "image/DJ-63.png"
    1100 - 1200 = "image/DJ-64.png"
    1200 - 1300 = "image/DJ-65.png"
    1300 - 1400 = "image/DJ-66.png"
    1400 - 1500 = "image/DJ-67.png"
    1500 - 1600 = "image/DJ-68.png"
    1600 - 1700 = "image/DJ-69.png"
    1700 - 1800 = "image/DJ-70.png"
    1800 - 1900 = "image/DJ-71.png"
    1900 - 2000 = "image/DJ-72.png"
    2000 - 2100 = "image/DJ-73.png"
    2100 - 0000 = "image/DJ-00.png"

    Sat - 16 March 2009
    0000 - 0900 = "image/DJ-00.png"
    0900 - 1000 = "image/DJ-74.png"
    1000 - 1100 = "image/DJ-75.png"
    1100 - 1200 = "image/DJ-76png"
    1200 - 1300 = "image/DJ-77.png"
    1300 - 1400 = "image/DJ-78.png"
    1400 - 1500 = "image/DJ-79.png"
    1500 - 1600 = "image/DJ-80.png"
    1600 - 1700 = "image/DJ-81.png"
    1700 - 1800 = "image/DJ-82.png"
    1800 - 1900 = "image/DJ-83.png"
    1900 - 2000 = "image/DJ-84.png"
    2000 - 2100 = "image/DJ-85.png"
    2100 - 0000 = "image/DJ-00.png"

    and all over the following week... Keep in mind that every day will have a different image. And yes, I do have 365 images to swap.

    Can anyone help?

    Thanks in advance,
    Frank

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Naming your image files according to the date and time they should be shown makes things much simpler. For example, if you name the image that should be shown from 11 to 12 on 13 March 2009 like DJ-11130309.png, you can use
    PHP Code:
    $image = (date(H) < || date(H) > 21) ? "DJ-00.png" "DJ-".date(Hdmy).".png"
    and $image will always hold the right filename.

  • Users who have thanked venegal for this post:

    matafy (05-01-2009)

  • #3
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts
    This makes sense. Thank you very much. What would the full code look like using your example if?

    Would it look something like this for Sun, 10 March 2009:

    <?PHP
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-09100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-10100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-11100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-12100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-13100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-14100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-15100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-16100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-17100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-18100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-19100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-20100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 9 || date(H) > 21) ? "img/DJ-21100309.png" : "DJ-".date(Hdmy).".png";
    $image = (date(H) < 21 || date(H) > 9) ? "img/DJ-00.png" : "DJ-00.png";
    ?>
    Last edited by matafy; 05-01-2009 at 05:27 AM.

  • #4
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    No, it's much simpler than that. It's really just the one line I gave you, for all the days and all the hours.

    I've written it with ternary conditional notation to make it shorter; maybe it's easier to understand if I wrote it more verbosely:

    PHP Code:
    // Is it between 21 and 9 o'clock right now?
    if (date(H) < || date(H) > 21) {
    // then make $image the standard image name "DJ-00.png"
        
    $image "DJ-00.png";
    } else {
    // else make $image the current image name in the format "DJ-[hhddmmyy].png"
    // (the same format according to which you named your image files)
        
    $image "DJ-".date(Hdmy).".png";


  • #5
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Oh, I understand it now. Now I guess the only question I have is how would I call the image from my server? This is my directory...

    my server/my webpage/img

    Wouldn't I have to put my directory in the script.

    $image = "img/DJ-00.png";
    $image = "img/DJ-".date(Hdmy).".png";

  • #6
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Yeah, how you handle your image path is completely at your discretion. If it's a fixed path that won't change, you can put it right into that snippet like
    PHP Code:
    $image = (date(H) < || date(H) > 21) ? "img/DJ-00.png" "img/DJ-".date(Hdmy).".png"
    or when it might be changed later on you may want leave it variable like
    PHP Code:
    $imagePath "img/";
    $image = (date(H) < || date(H) > 21) ? $imagePath."DJ-00.png" $imagePath."DJ-".date(Hdmy).".png"
    There are 50 ways to do this, depending on how much abstraction you want put into that for later changa- and portability.

  • #7
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Smile

    Would this script be good enough if I just wanted to repeat the same images around the clock for that day?

    <?PHP

    $imagePath = "img/";

    if (date(H)-8 < 9 || date(H)-8 > 21) {

    $imagePath."DJ-00.png";

    } else {

    $imagePath."DJ-".date(DH).".png";
    }

    ?>



    The file names would now be "DJ-Sun09.png"
    "DJ-Sun10.png"
    "DJ-Sun11.png"
    "DJ-Sun12.png"
    "DJ-Sun13.png"
    "DJ-Sun14.png"
    "DJ-Sun15.png"
    "DJ-Sun16.png"
    "DJ-Sun17.png"
    "DJ-Sun18.png"
    "DJ-Sun19.png"
    "DJ-Sun20.png"
    "DJ-Sun21.png"

    I added the GMT to reflect California's time. I changed the date format so I can repeat the images. The calculation of images I would have to upload was bigger than I originally thought. So, I decided to repeat the same images week after week. Does this look right?

  • #8
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    It looks like it should work, except you are evaluating those strings without doing anything with them. You will want to either store the filename with path in some variable like

    PHP Code:
    $imagePath "img/";
    if (
    date(H)-|| date(H)-21) {
        
    $imagePathAndFilename $imagePath."DJ-00.png";
    } else {
        
    $imagePathAndFilename $imagePath."DJ-".date(DH).".png";
    }
    echo 
    $imagePathAndFilename
    or make it a function returning the filename with path like
    PHP Code:
    function currentImage(){
        
    $imagePath "img/";
        if (
    date(H)-|| date(H)-21) {
            return 
    $imagePath."DJ-00.png";
        } else {
            return 
    $imagePath."DJ-".date(DH).".png";
        }
    }
    echo 
    currentImage(); 

  • #9
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts
    I used both of the scripts and I got the text:

    img/DJ-Fri22.png

    and not the actual image.

  • #10
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Well it's really hard to tell someones proficiency and how much you have to spell things out. I echoed the string out so you can see the usage of the two examples. If you want to output the actual picture, you'll have to put the filename in some html, like

    Code:
    <img src="<?php echo currentImage();?>" alt="DJ image" />

  • Users who have thanked venegal for this post:

    matafy (05-03-2009)

  • #11
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks once again and Thank you for your time. I'm sure you get annoyed when you have to think about something as simple as this. I appreciate all your help. I ended using folders to help me sort out the images.

    Here is what I ended up with.

    function currentImage(){
    $imagePath = "img/";
    if (date(H) < 09 || date(H) > 21) {
    return $imagePath."".date(D)."/".date(H).".png";
    } else {

    return $imagePath."".date(D)."/".date(H).".png";
    }
    }

    <img src="<?php echo currentImage();?>">

    This scripted worked out perfect for me.

    Would I be able to swap html or php files with the same method?

  • #12
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    That's quite alright; if I were getting annoyed, I would simply stop replying.

    In your code the if statement is superfluous -- both the if and the else return the same thing. Originally the if statement was there in order to return a standard image between 21 and 9 o'clock. If you now really do have an image for every hour (even at night), you can kick the if/else.

    Also concatenating an empty string literal into your filename doesn't make much sense. Use $imagePath.date(D) instead of $imagePath."".date(D).

    And I wish you hadn't changed the html I gave you. In order for your code to be valid, <img>s need to have an 'alt' property, and they must be properly closed (/> instead of just >)

    Regarding your questions: Like you did with the image filenames, you can certainly put the names of html- or php files into a php variable with the same method. The real question is, how you want to use that variable. With the image filenames, you put them into <img> tags in order to show them in the browser. What do you want to do with the html and php files? If they should be links, that should change with every hour, you could echo the variable in the href property of an <a> tag.

  • #13
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Your right! One thing though. The $imagePath.date(D) instead of $imagePath."".date(D). Didn't seem to work for me. I first put the .date(D) and nothing. Then I put "".date and it targeted the folder I was looking for.

    Well, to be honest. This is what I'm trying to accomplish. If you go to latalkradio.com and click right on through till you get to the who is DJing. They have a rotating image along with the rotating ip stream. I like that and would like to use that same method for my website.

    I figured since you helped me tremendously with this script you can show me how I can do the very same thing they have... If it isn't to much to ask, I would greatly appreciate that.

  • #14
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Yeah, if you just put .date(D) in your code, it won't work. "." is the concatenation operator, it has to be between two strings you want to concatenate. Thus putting "".date(D) seemed to solve your problem, but you really should have just put date(D) there.

    You already have the rotating image, so all that's left is the rotating stream. Well I guess you won't use the same method for that, but always use the same link and let the .php responsible for the stream decide, which one to serve. But I can't tell you any specifics unless you elaborate on how you are planning on serving that stream.

  • #15
    New Coder
    Join Date
    Apr 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts
    You know what? I found my problem. I didn't put the "." in the script. I accidently left it out. This is what it looked like when I used it $imagePathdate(D) It now works just like you said.

    Ooops!

    As far as the ip stream. I'm still working on whether to set my own cpu as a server to stream or look for some type of shoutcast hosting provider, but till then here is what I'm looking at.

    Monday Schedule 1:

    0900 - 1000 = Dj 1 (on ip 127.0.0.2:8000) ip provided by the DJ's cpu at home
    1000 - 1100 = Dj 2 (on ip 127.0.0.3:8000)
    1100 - 1200 = Dj 3 (on ip 127.0.0.4:8000)
    1200 - 1300 = Dj 4 (on ip 127.0.0.5:8000)
    1300 - 1400 = Dj 5 (on ip 127.0.0.6:8000)
    1400 - 1500 = Dj 6 (on ip 127.0.0.6:8000)
    1500 - 1600 = Dj 7 (on ip 127.0.0.7:8000)
    1600 - 1700 = Dj 8 (on ip 127.0.0.8:8000)
    1700 - 1800 = Dj 9 (on ip 127.0.0.9:8000)
    1800 - 1900 = Dj 10 (on ip 127.0.1.0:8000)
    1900 - 2000 = Dj 11 (on ip 127.0.1.1:8000)
    2000 - 2100 = Dj 12 (on ip 127.0.1.2:8000)

    Monday Schedule: Repeated

    2100 - 0900 = Djs (on ip 127.1.2.3:8000)

    ------------------------------------------

    Tuesday Schedule 2:

    0900 - 1000 = Dj 13 (on ip 127.0.1.3:8000)
    1000 - 1100 = Dj 14 (on ip 127.0.1.4:8000)
    1100 - 1200 = Dj 15 (on ip 127.0.1.5:8000)
    1200 - 1300 = Dj 16 (on ip 127.0.1.6:8000)
    1300 - 1400 = Dj 17 (on ip 127.0.1.7:8000)
    1400 - 1500 = Dj 18 (on ip 127.0.1.8:8000)
    1500 - 1600 = Dj 19 (on ip 127.0.1.9:8000)
    1600 - 1700 = Dj 20 (on ip 127.0.2.0:8000)
    1700 - 1800 = Dj 21 (on ip 127.0.2.1:8000)
    1800 - 1900 = Dj 22 (on ip 127.0.2.2:8000)
    1900 - 2000 = Dj 23 (on ip 127.0.2.3:8000)
    2000 - 2100 = Dj 24 (on ip 127.0.2.4:8000)

    Tuesday Schedule: Repeated

    2100 - 0900 = Djs (on ip 127.1.2.3:8000)

    ------------------------------------------

    And so on for the rest of the week. Sundays would be prerecorded randomly selected files starting at 0900 to Monday 0900. I should have a total of 72 projected Djs by 2100 Saturday.

    I just may consider using a webcam.
    Last edited by matafy; 05-03-2009 at 10:02 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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