画电子钟
<!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");
$im = imagecreatetruecolor(250,250);
$white = imagecolorallocate($im,0xFF,0xFF,0xFF);
$red = imagecolorallocate($im,255,0,0);
$blue = imagecolorallocate($im,0,0,0xFF);
$green = imagecolorallocate($im,0,0xFF,0);
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);
$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);
header("Content-Type:images/gif");
imagegif($im);
imagedestroy($im);
?>