显示页面代码
<!DOCTYPE html >
<html>
<head>
<title>time</title>
</head>
<body>
<img id="time" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="index.php"/>
<script>
setInterval(function(){
document.getElementById('time').class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="index.php?"+Math.random();
},1000);
</script>
</body>
</html>
画图页面代码
/*
* 绘制时钟
*/
//获取系统时间
date_default_timezone_set('PRC');
$h = date('H');
$i = date('i');
$s = date('s');
//1.创建资源 画布的大小
$img = imagecreatetruecolor(200, 250);
$white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
$red = imagecolorallocate($img, 255, 0, 0);
$blue = imagecolorallocate($img,0, 0, 0xFF);
$pink = imagecolorallocate($img, 0xFF, 0, 0xFF);
imagefill($img,0,0,$white);
//画椭圆
imageellipse($img, 100, 100, 190, 190, $blue);
imagefilledellipse($img, 100, 100, 4, 4, $blue);
imagestring($img, 4, 95, 8, '12', $pink);
imagestring($img, 4, 175, 95, '03', $pink);
imagestring($img, 4, 95, 175, '06', $pink);
imagestring($img, 4, 11, 95, '09', $pink);
//秒针
$len = 80;
$a = $len*sin(pi()/30*$s);//注意是秒针与竖线形成的夹角 每秒走过6度 sin()里面是按弧度作为参数 要将度换算成弧度
$b = $len*cos(pi()/30*$s);
$x = 100 + $a;//秒针线末端x轴的坐标
$y = 100 - $b;//秒针线末端y轴的坐标
//分钟
$len1 =1;
$a1 = $len*sin(pi()/1800*$s);
$b1 = $len*cos(pi()/1800*$s);
$x1 = 100 + $a1;//秒针线末端x轴的坐标
$y1 = 100 - $b1;//秒针线末端y轴的坐标
//秒针
imageline($img, 100, 100, $x, $y, $red);
//指针
imageline($img, 100, 100, $x1, $y1,$blue);
//数字的时间
imagestring($img, 5, 20, 230, "now:{$h}:{$i}:{$s}",$red);
//4.保存 或输出给浏览器 写第二个参数就是保存
header('Content-type:image/jpeg');
imagepng($img);
//5.释放资源
imagedestroy($img);
结果为
共同学习,写下你的评论
评论加载中...
作者其他优质文章