...

View Full Version : Moving a image across by month



I3arry
07-06-2007, 09:54 PM
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

$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 (15, 0, $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 > 0 && $display_days > 0) {
$and_3 = "and";
}

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

if ($display_years > 0 && $display_months > 0 && $display_weeks == 0 && $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 ($im, 0, 0, 0);

$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 ($im, 10, 0, $TextX+10, $TextY+24, $text_color, $FontFile, $message);
imagecopy ($im, $tickim, $TickerImgX ,$TickerImgY ,0 , 0, 31, 42);

Imagepng ($im);
ImageDestroy ($im);
}
echo "Image Not Found";

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum