<?php
/**
*
* php gd函数的使用
*
* */
//获取系统时间
date_default_timezone_set('PRC');
$h = date('h');
$i = date('i');
$s = date('s');
// 1. 创建画布
$im = imagecreatetruecolor(300,300);
// 2.创建颜色
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);
$white = imagecolorallocate($im,255,255,255);
$iColor = imagecolorallocate($im,0,188,212);
$hColor = imagecolorallocate($im,63,81,181);
// 3.填充颜色
imagefill($im, 0, 0, $white);
// 4. 画圆形
imageellipse($im, 150, 150, 290, 290, $black);
imagefilledellipse($im, 150, 150, 8, 8, $black);
// 表盘数字
imageellipse($im, 150, 150, 250, 250, $white);
$du = 360/12;
for($j=1;$j<=12;$j++){
$r = 120;
$ox = $r*sin(pi()/180*$du*$j);
$oy = $r*cos(pi()/180*$du*$j);
$x = 145+$ox;
$y = 144-$oy;
imagestring($im, 7, $x, $y, $j, $red);
}
// 秒针
$r = 120;
$ox = $r*sin(pi()/30*$s);
$oy = $r*cos(pi()/30*$s);
$x = 150+$ox;
$y = 150-$oy;
// 画秒针
imageline($im, 150, 150, $x, $y, $red);
// 分针
$ir = 100;
$iox = $ir*sin(pi()/1800*($i*60+$s));
$ioy = $ir*cos(pi()/1800*($i*60+$s));
$ix = 150+$iox;
$iy = 150-$ioy;
// 画分针
imageline($im, 150, 150, $ix, $iy, $iColor);
// 时针
$hr = 80;
$hox = $hr*sin(pi()/(1800*12)*($h*3600+$i*60+$s));
$hoy = $hr*cos(pi()/(1800*12)*($h*3600+$i*60+$s));
$hx = 150+$hox;
$hy = 150-$hoy;
// 画时针
imageline($im, 150, 150, $hx, $hy, $hColor);
// 输出、保存
header('Content-type: images/png');
imagepng($im);
// 销毁
imagedestroy($im);
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交