Código fuente de 'Reloj analogico.php'
<html>
<head>
<title>Reloj analogico</title>
</head>
<body style="font-family: Arial; font-size: 9pt">
<center><b><font face="Arial" size="3">Reloj analogico</font></b>
<br><br>
<?php
/* Clock & Date Image v1
By Richard James Kendall
Bugs to richard@richardjameskendall.com
Free to use, please acknowledge me
Edit the default variables (if you want).
It is ready to go!
*/
// the only setting is the default clock width, this is used if no
// width is specified by the requesting party
$clock_width = 150;
$show_date = true;
if (isset($_GET["width"])) {
$clock_width = $_GET["width"];
}
if (isset($_GET["date"])) {
$show_date = $_GET["date"];
}
$clock_origin = (17 + ($clock_width / 2));
function calcrad($u, $t) {
$u -= ($t / 4);
if ($u < 0) {
$u += $t;
}
return deg2rad(abs((360 / $t)) * $u);
}
$im = imagecreate(($clock_width + 110), ($clock_width + 40));
$white = imagecolorallocate($im, 255, 255, 255);
$clock_b_col = imagecolorallocate($im, 0, 0, 0);
$clock_hh_col = imagecolorallocate($im, 130, 130, 130);
$clock_mh_col = imagecolorallocate($im, 200, 200, 200);
$clock_sh_col = imagecolorallocate($im, 144, 192, 232);
//imagearc($im, $clock_origin, $clock_origin, $clock_width, $clock_width, 0, 360, $clock_b_col);
imagerectangle($im, 0, 0, ($clock_width + 110) - 1, ($clock_width + 40) - 1, $clock_b_col);
$hour = date("g");
$minute = date("i");
$second = date("s");
$h_angle = calcrad($hour, 12);
$m_angle = calcrad($minute, 60);
$s_angle = calcrad($second, 60);
$h_adjust = deg2rad(((360 / 12) / 60) * $minute);
$hour_x = (($clock_width / 2) - (0.2 * $clock_width)) * cos($h_angle + $h_adjust) + $clock_origin;
$hour_y = (($clock_width / 2) - (0.2 * $clock_width)) * sin($h_angle + $h_adjust) + $clock_origin;
$minute_x = (($clock_width / 2) - (0.05 * $clock_width)) * cos($m_angle) + $clock_origin;
$minute_y = (($clock_width / 2) - (0.05 * $clock_width)) * sin($m_angle) + $clock_origin;
$second_x = (($clock_width / 2) - (0.05 * $clock_width)) * cos($s_angle) + $clock_origin;
$second_y = (($clock_width / 2) - (0.05 * $clock_width)) * sin($s_angle) + $clock_origin;
imageline($im, $clock_origin, $clock_origin, $hour_x, $hour_y, $clock_hh_col);
imageline($im, $clock_origin, $clock_origin, $minute_x, $minute_y, $clock_mh_col);
$line_style = array($clock_sh_col, $clock_sh_col, $clock_sh_col, $clock_sh_col, $clock_sh_col, $white, $white, $white, $white, $white);
imagesetstyle($im, $line_style);
imageline($im, $clock_origin, $clock_origin, $second_x, $second_y, IMG_COLOR_STYLED);
for($i = 1;$i <= 12;$i++) {
$n_angle = calcrad($i, 12);
$num_x = (($clock_width / 2) + 5) * cos($n_angle) + $clock_origin;
$num_y = (($clock_width / 2) + 5) * sin($n_angle) + $clock_origin;
imagestring($im, 1, $num_x, $num_y, $i, $clock_b_col);
}
if ($show_date) {
$d_angle = calcrad(3, 12);
$date_x = (($clock_width / 2) + 20) * cos($d_angle) + $clock_origin;
$date_y = ($clock_width / 2) * sin($d_angle) + $clock_origin;
imagestring($im, 2, $date_x, $date_y - 4, date("d/m/Y"), $clock_b_col);
}
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
</center>
</body>
</html>