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.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moving a image across by month

    This is a ticker to count up months untill birthdays, I have used imagecopy to create a slider that move up to the next month (number) each month but for some reason he seems to be a month ahead
    PHP Code:
    <?php

    $startmonth 
    "$_GET[month]";
    $startdate "$_GET[date]";
    $startyear "$_GET[year]";
    $name "$_GET[name]";
    $img "$_GET[img]";

    $monthDays[1] = 31;  $monthDays[2] = 28;  $monthDays[3] = 31;
    $monthDays[4] = 30;  $monthDays[5] = 31;  $monthDays[6] = 30;
    $monthDays[7] = 31;  $monthDays[8] = 31;  $monthDays[9] = 30;
    $monthDays[10] = 31$monthDays[11] = 30$monthDays[12] = 31;

    $startDate "$startmonth $startdate $startyear";
    $startTimestamp strtotime $startDate );
    $timeDifference time() - $startTimestamp;

    $years 0;
    $months 0;
    $weeks 0;
    $days 0;
    $hours 0;
    $minutes 0;
    $seconds 0;
    $secondsPerDay 86400;

    while ( 
    $timeDifference >= ($secondsPerDay*365) )
    {
        
    $years++;
        
    $timeDifference -= ($secondsPerDay*365);
    }

    $monthNum intval(strftime"%m"$startTimestamp ));
    while ( 
    $timeDifference >= ($secondsPerDay*$monthDays[$monthNum]) )
    {
        
    $months++;
        
    $timeDifference -= ($secondsPerDay*$monthDays[$monthNum]);
        if ( ++
    $monthNum 12 )
            
    $monthNum 1;
    }

    while ( 
    $timeDifference >= ($secondsPerDay*7) )
    {
        
    $weeks++;
        
    $timeDifference -= ($secondsPerDay*7);
    }

    $days floor($timeDifference/$secondsPerDay);
    $timeDifference -= $days $secondsPerDay;

    $hours floor($timeDifference/60/60);
    $timeDifference -= $hours 60 60;
    $minutes floor($timeDifference%$secondsPerDay/60);
    $timeDifference -= $minutes 60;
    $seconds $timeDifference;

    $FontFile="font/arial.ttf";

    $ImageURL="http://www.example.net/ticker/img/ticker.png";
    $TextX=0;
    $TextY=42;

    $TickerURL="http://www.example.net/ticker/img/slider.png";
    $TickerImgX=20;
    $TickerImgY=5;


    $size ImageTTFBbox (150$FontFile"heyheyhey");  // size, angle, font, text
    $im_x=abs($size[4]-$size[0]);
    $im_y=abs($size[5]-$size[1]);

    if (
    $years == 1) {
       
    $display_years "$years year";
       } elseif (
    $years 1) {
       
    $display_years "";
          } else {
       
    $display_years"$years years";
       }

    if (
    $months == 1) {
       
    $display_months "$months month";
       } elseif (
    $months 1) {
       
    $display_months "";
          } else {
       
    $display_months "$months months";
       }

    if (
    $weeks == 1) {
       
    $display_weeks "$weeks week";
       } elseif (
    $weeks 1) {
       
    $display_weeks "";
          } else {
       
    $display_weeks"$weeks weeks";
       }

    if (
    $days == 1) {
       
    $display_days "$days day";
       } elseif (
    $days 1) {
       
    $display_days "";
          } else {
       
    $display_days"$days days";
       }

    // the next section checks for where the and should be put

    $and_1 "";
    $and_2 "";
    $and_3 "";

    if (
    $display_years $display_months $display_weeks && $display_days 0) {
       
    $and_3 "and";
       }

    if (
    $display_years $display_months && $display_weeks && $display_days == 0) {
       
    $and_2 "and";
       }

    if (
    $display_years && $display_months && $display_weeks == && $display_days == 0) {
       
    $and_1 "and";
       }


    if (
    substr($ImageURL,strlen($ImageURL)-3,3)=="png") {
       
    Header("Content-type: image/png");
       
    Header("Expires: " gmdate("D, d M Y H:i:s"time() + 900) . " GMT");

       
    $im_size GetImageSize ($ImageURL);
       
    $imageWidth $im_size[0];
       
    $imageHeight $im_size[1];

    if (
    $months 12) { $months $months/$years
    }
    $tick_amount = ($imageWidth-20)/12;
    for (
    $i=0;$i<$months;$i++) {
    $TickerImgX += $tick_amount;

    }

       
    $im ImageCreateFromPNG($ImageURL);
       
    $tickim ImageCreateFromPNG($TickerURL);
       
       
    $text_color imagecolorclosest ($im000);

       
    $message "$name is $display_years $display_months $display_weeks $display_days old!";

       if (
    $TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
       if (
    $TextY>$imageHeight){$TextY=$imageHeight-2;}
          
          
    imagettftext ($im100$TextX+10$TextY+24$text_color$FontFile$message);
          
    imagecopy ($im$tickim$TickerImgX ,$TickerImgY ,03142);
        
        
    Imagepng ($im);
        
    ImageDestroy ($im);
       }
       echo 
    "Image Not Found";

    ?>
    Attached Thumbnails Attached Thumbnails Moving a image across by month-ticker.png  


 

Posting Permissions

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