<?
ob_start();
$width = 400; $height=400;	
$im = ImageCreateTrueColor($width, $height);

$color_array = array();
$color_array[] = imagecolorallocate($im, 255, 255, 255);
$color_array[] = imagecolorallocate($im, 0, 0, 0);

imagefill($im,0,0,$color_array[0]);
imagestring($im,3,0,0,"Click refresh if the colors are not clear",
	$color_array[1]);
imagesetthickness($im,2);
for ($i=1;$i<3;$i++)
{
	do
	{
		$random1 = mt_rand(0,250);
		$random2 = mt_rand(0,250);
		$random3 = mt_rand(0,250);
		$random_color = imagecolorallocate($im, $random1, $random2, $random3);
	}
	while (in_array($random_color,$color_array));
	$color_array[] = $random_color;
}
$date = getdate();
$year_day = $date['yday'];
$hours = $date['hours'];
$minutes = $date['minutes'];
$percentage_days = $year_day / 365;
$percentage_time = ($hours * 60 + $minutes)/(24 * 60);

// Now draw rectangle for percentage of days of the year that passed:
$start_x = 50; $start_y = 50;
$length = 200;
$width = 30;
imagerectangle($im,$start_x,$start_y,$start_x+$length,$start_y+$width,
		$color_array[1]);
imageline($im,$start_x,$start_y+$width+3,$start_x,$start_y+$width,$color[1]);
imagestring($im,3,$start_x,$start_y+$width + 2,"0",$color[1]);
imageline($im,$start_x+50,$start_y+$width+3,$start_x+50,$start_y+$width,$color[1]);
imagestring($im,3,$start_x+50,$start_y+$width + 2,"25%",$color[1]);
imageline($im,$start_x+100,$start_y+$width+3,$start_x+100,$start_y+$width,$color[1]);
imagestring($im,3,$start_x+100,$start_y+$width + 2,"50%",$color[1]);
imageline($im,$start_x+150,$start_y+$width+3,$start_x+150,$start_y+$width,$color[1]);
imagestring($im,3,$start_x+150,$start_y+$width + 2,"75%",$color[1]);
imageline($im,$start_x+200,$start_y+$width+3,$start_x+200,$start_y+$width,$color[1]);
imagestring($im,3,$start_x+200,$start_y+$width + 2,"100%",$color[1]);


imagefilledrectangle($im,$start_x,$start_y,$start_x+$percentage_days*$length,
			$start_y+$width,$color_array[2]);

// Convert the percentage to integer:
$percent=round($percentage_days*100,2);
$start_y = $start_y+$width+15;
imagestring($im,3,$start_x,$start_y,
	"$percent% days of the year passed",$color_array[1]);

// Now draw circle for percentage of time of the day that passed:
$diameter = 200;
$center_x = $start_x + $diameter/2; $center_y = 150 + $diameter/2;
$begin_degree = 0; $end_degree = 360; $color = $color_array[1];
imageArc($im,$center_x,$center_y,$diameter,$diameter,$begin_degree,
	$end_degree,$color);

$begin_degree = 0; $end_degree = $percentage_time * 360; 
$color = $color_array[3];
imageFilledArc($im,$center_x,$center_y,$diameter,$diameter,
		$begin_degree,$end_degree,$color,IMG_ARC_PIE);
imageArc($im,$center_x,$center_y,$diameter,$diameter,$begin_degree,
        $end_degree,$color);

imageline($im,$center_x+$diameter/2,$center_y,$center_x+$diameter/2+3,$center_y,$color[1]);
imagestring($im,3,$center_x+$diameter/2+5,$center_y,"0%",$color[1]);

$rad_degree = 45 * M_PI / 180;
$x1 = $center_x+($diameter/2)*cos($rad_degree); 
$y1 = $center_y+($diameter/2)*sin($rad_degree);
imageline($im,$x1,$y1,$x1+5,$y1,$color[1]);
imagestring($im,3,$x1+5,$y1,"12.5%",$color[1]);

$rad_degree = 90 * M_PI / 180;
$x1 = $center_x+($diameter/2)*cos($rad_degree);
$y1 = $center_y+($diameter/2)*sin($rad_degree);
imageline($im,$x1,$y1,$x1,$y1+5,$color[1]);
imagestring($im,3,$x1,$y1+5,"25%",$color[1]);

$rad_degree = 135 * M_PI / 180;
$x1 = $center_x+($diameter/2)*cos($rad_degree);
$y1 = $center_y+($diameter/2)*sin($rad_degree);
imageline($im,$x1,$y1,$x1-5,$y1,$color[1]);
imagestring($im,3,$x1-30,$y1,"37.5%",$color[1]);

$rad_degree = 180 * M_PI / 180;
$x1 = $center_x+($diameter/2)*cos($rad_degree);
$y1 = $center_y+($diameter/2)*sin($rad_degree);
imageline($im,$x1,$y1,$x1-5,$y1,$color[1]);
imagestring($im,3,$x1-30,$y1,"50%",$color[1]);

$rad_degree = 225 * M_PI / 180;
$x1 = $center_x+($diameter/2)*cos($rad_degree);
$y1 = $center_y+($diameter/2)*sin($rad_degree);
imageline($im,$x1,$y1,$x1-5,$y1,$color[1]);
imagestring($im,3,$x1-40,$y1,"62.5%",$color[1]);

$rad_degree = 270 * M_PI / 180;
$x1 = $center_x+($diameter/2)*cos($rad_degree);
$y1 = $center_y+($diameter/2)*sin($rad_degree);
imageline($im,$x1,$y1,$x1,$y1-5,$color[1]);
imagestring($im,3,$x1+2,$y1-15,"75%",$color[1]);

$rad_degree = 315 * M_PI / 180;
$x1 = $center_x+($diameter/2)*cos($rad_degree);
$y1 = $center_y+($diameter/2)*sin($rad_degree);
imageline($im,$x1,$y1,$x1+5,$y1,$color[1]);
imagestring($im,3,$x1+10,$y1,"87.5%",$color[1]);


$percent=round($percentage_time*100,2);
$start_x = $center_x-$diameter/2;
$start_y = 20+$center_y+$diameter/2;
imagestring($im,3,$start_x,$start_y,
        "$percent% time of the day passed",$color_array[1]);

Header('Content-type: image/png');
Imagepng($im);

	// Save image to a file
  	#ImagePng($im,"/home/abu-jeib/proposals/abc.png");
  
  ImageDestroy($im);
ob_end_flush();
?>

