画电子钟

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>时钟</title>
</head>
<body>
	<img id="clock">
	<script>
		setInterval(function(){
			document.getElementById('clock').src = './04-clock.php?'+Math.random();
		},1000)
	</script>
</body>
</html>

04-clock.php

<?php 
// 获取系统时间
date_default_timezone_set("PRC");
$h = date("H");
$i = date("i");
$s = date("s");

// 1
$im = imagecreatetruecolor(250,250);

// 2
$white = imagecolorallocate($im,0xFF,0xFF,0xFF);
$red = imagecolorallocate($im,255,0,0);
$blue = imagecolorallocate($im,0,0,0xFF);
$green = imagecolorallocate($im,0,0xFF,0);
// 3
imagefill ( $im ,  0 ,  0 ,  $white );

//圆形
imageellipse($im, 100, 100, 190,190, $blue);
imageellipse($im, 100, 100, 4,4, $blue);

//时间
imagestring($im, 3, 95, 8, "12", $blue);
imagestring($im, 3, 180, 95, "03", $blue);
imagestring($im, 3, 95, 180, "06", $blue);
imagestring($im, 3, 11, 95, "09", $blue);

//秒针 2PI = 360
$len = 80;
$a = $len*sin(pi()/180*6*$s);
$b = $len*cos(pi()/180*6*$s);
$x = 100 + $a;
$y = 100 - $b;

imageline($im, 100, 100, $x, $y, $red);

// 数字时间
imagestring($im, 5, 50, 50, "Now:{$h}:{$i}:{$s}", $red);

// 4
header("Content-Type:images/gif");
imagegif($im);

// 5
imagedestroy($im);
?>