+ Reply to Thread
Results 1 to 6 of 6

Thread: Display time by using images

  1. #1
    Jaan Guest

    Display time by using images

    Attached Files Attached Files
    Last edited by Jaan; 06-08-2010 at 10:34 AM.

  2. CODECALL Circuit advertisement

     
  3. #2
    Whitey's Avatar
    Whitey is offline Programming Professional
    Join Date
    Feb 2008
    Location
    Loveland, Colorado
    Posts
    254
    Rep Power
    18

    Re: Display time by using images

    Only 1 thing i would suggest changing..
    You have to "refresh" the page for it to see the "time change".
    If you can bind it with AJAX that would be a really Good tutorial!

  4. #3
    Jordan Guest

    Re: Display time by using images

    Reloading an image with JavaScript/Image would look a bit choppy. You could set the clock as a background and make the arms CSS classes or IDs. With AJAX/JavaScript you could move them to new locations.

    Nice bit of code though!

  5. #4
    Join Date
    Apr 2008
    Posts
    789
    Blog Entries
    5
    Rep Power
    24

    Re: Display time by using images

    Instead of giving a path for each number just catenate the string to get a path, like this:
    "http://forum.codecall.net/images/" . number . ".jpg"
    note: I'm assuming that php uses the . operator for catenation, like perl.

  6. #5
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Display time by using images

    Quote Originally Posted by Aereshaa View Post
    Instead of giving a path for each number just catenate the string to get a path, like this:
    "http://forum.codecall.net/images/" . number . ".jpg"
    note: I'm assuming that php uses the . operator for catenation, like perl.
    That would work, but I don't see any advantage to either.

  7. #6
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Display time by using images

    A few things I noticed that might be of an improvement. Rather than
    Code:
    // Get date
    $date date("h:i");
    // Brake it from :
    $date_slice explode(":"$date);
    // First pair of numbers
    $firstpart $date_slice['0'];
    // Second pair of numbers
    $secondpart $date_slice['1'];
    // Let's get first number of first pair
    $numbers = array();
    // Now let's get numbers
    $numbers['first_part1'] = substr($firstpart01);
    $numbers['second_part1'] = substr($firstpart, -12);
    $numbers['first_part2'] = substr($secondpart01);
    $numbers['second_part2'] = substr($secondpart, -12); 
    You can simply do
    Code:
    $date date("h:i");
    $numbers['first_part1']  = $date[0];
    $numbers['second_part1'] = $date[1];
    $numbers['first_part2']  = $date[3];
    $numbers['second_part2'] = $date[4]; 



    A slightly different approach might be to take advantage of the built in image functions.
    image.php
    Code:
    <?php
    $im 
    imagecreate(10030);
    $bg imagecolorallocate($im255255255);
    $textcolor imagecolorallocate($im000);
    imagestring($im500date("h:i"), $textcolor);
    header("Content-type: image/png");
    imagepng($im);
    ?>
    index.php
    Code:
    <img src="image.php" /> 

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 213
    Last Post: 04-14-2011, 07:57 PM
  2. Replies: 3
    Last Post: 02-07-2011, 11:29 AM
  3. Replies: 0
    Last Post: 04-30-2010, 12:08 AM
  4. display images sequentially using PHP and MySQL
    By jhanjon in forum PHP Development
    Replies: 2
    Last Post: 10-08-2009, 12:11 PM
  5. Replies: 2
    Last Post: 05-10-2009, 09:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

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