<?
ob_start();
$image_width = 400; $image_height=500;	
$im = ImageCreateTrueColor($image_width, $image_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<6;$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'];
$seconds = $date['seconds'];
$percentage_days = $year_day / 365;
$percentage_hours = $hours / 24;
$percentage_minutes = $minutes / 60;
$percentage_seconds = $seconds / 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]);
for ($i = 0; $i <= 4; $i++)
{
	imageline($im,$start_x + 50 * $i,$start_y+$width+3,$start_x + 50 * $i,$start_y+$width,$color[1]);
	$p = $i*25;
        imagestring($im,3,$start_x + 50 * $i,$start_y+$width + 2,"$p%",$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 rectangle for percentage of hours of the day that passed:
$start_x = 50; $start_y = 150;
$length = 200;
$width = 30;
imagerectangle($im,$start_x,$start_y,$start_x+$length,$start_y+$width,
		$color_array[1]);
for ($i = 0; $i <= 4; $i++)
{
	imageline($im,$start_x + 50 * $i,$start_y+$width+3,$start_x + 50 * $i,$start_y+$width,$color[1]);
	$p = $i*25;
	imagestring($im,3,$start_x + 50 * $i,$start_y+$width + 2,"$p%",$color[1]);
}
imagefilledrectangle($im,$start_x,$start_y,$start_x+$percentage_hours*$length,$start_y+$width,$color_array[3]);

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

//================
// Now draw rectangle for percentage of minutes of the hour that passed:
$start_x = 50; $start_y = 250;
$length = 200;
$width = 30;
imagerectangle($im,$start_x,$start_y,$start_x+$length,$start_y+$width,
		$color_array[1]);
for ($i = 0; $i <= 4; $i++)
{
	imageline($im,$start_x + 50 * $i,$start_y+$width+3,$start_x + 50 * $i,$start_y+$width,$color[1]);
	$p = $i*25;
        imagestring($im,3,$start_x + 50 * $i,$start_y+$width + 2,"$p%",$color[1]);
}
imagefilledrectangle($im,$start_x,$start_y,$start_x+$percentage_minutes*$length,$start_y+$width,$color_array[4]);

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

//=============
// Now draw rectangle for percentage of seconds of the minute that passed:
$start_x = 50; $start_y = 350;
$length = 200;
$width = 30;
imagerectangle($im,$start_x,$start_y,$start_x+$length,$start_y+$width,
		$color_array[1]);
for ($i = 0; $i <= 4; $i++)
{
	imageline($im,$start_x + 50 * $i,$start_y+$width+3,$start_x + 50 * $i,$start_y+$width,$color[1]);
	$p = $i*25;
        imagestring($im,3,$start_x + 50 * $i,$start_y+$width + 2,"$p%",$color[1]);
}
imagefilledrectangle($im,$start_x,$start_y,$start_x+$percentage_seconds*$length,$start_y+$width,$color_array[5]);

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

//================
// Now send the image to the browser.


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();
?>
