Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $height = 450;
- $width = 450;
- $img = imagecreatetruecolor($width, $height);
- $black = imagecolorallocate($img, 0, 0, 0);
- $white = imagecolorallocate($img, 255, 255, 255);
- $red = imagecolorallocate($img, 255, 0, 0);
- $gray = imagecolorallocate($img, 105, 105, 105);
- imagefill($img, 0, 0, $black);
- $dx = $width / 2; // Zeropoint x
- $dy = $height / 2; // Zeropoint y
- $hr = 100; // Hour radius
- $mr = 120; // Minute radius
- $hour = date("G", time() + 3600);
- $min = intval(date("i", time() + 3600));
- $hdeg = 90 - 0.5 * ($hour * 60 + $min); // Hour degrees
- $mdeg = 90 - 6.0001 * ($hour * 60 + $min); // Minute degrees
- $hx = cos(deg2rad($hdeg)) * $hr; // Hour x-pos
- $hy = sin(deg2rad($hdeg)) * $hr; // Hour y-pos
- $mx = cos(deg2rad($mdeg)) * $mr; // Minute x-pos
- $my = sin(deg2rad($mdeg)) * $mr; // Minuty y-pos
- imagesetthickness($img, 5);
- imageline($img, $dx, $dy, $dx + $hx, $dy - $hy, $white); // Draw hour line
- imagesetthickness($img, 2);
- imageline($img, $dx, $dy, $dx + $mx, $dy - $my, $white); // Draw minute line
- imagesetthickness($img, 1);
- for($i = 0; $i < 60; $i++) { // Every minute (5th degree)
- $ld = 90 - 6.0001 * $i;
- $lx = cos(deg2rad($ld));
- $ly = sin(deg2rad($ld));
- imageline($img, $dx + $lx * 140, //x1
- $dy - $ly * 140, //y1
- $dx + $lx * 150, //x2
- $dy - $ly * 150, //y2
- $gray);
- if($i % 5 == 0) { // Every hour
- imagesetthickness($img, 3);
- imageline($img, $dx + $lx * 130, //x1
- $dy - $ly * 130, //y1
- $dx + $lx * 150, //x2
- $dy - $ly * 150, //y2
- $red);
- imagesetthickness($img, 1);
- $x = ($dx + $lx * 165);
- $y = ($dy - $ly * 165);
- imagestring($img, 3, $x - 3, $y - 5, preg_replace("/^0$/", "12", $i / 5), $gray);
- }
- }
- imageellipse($img, $dx, $dy, 300, 300, $white);
- imagestring($img, 5, $width / 2 - 20, 20, "Kello", $white);
- imagestring($img, 5, $width / 2 - 20, 35, date("H:i", time() + 3600), $white);
- header("Content-type: image/png");
- imagepng($img);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment