digital-clock-php-gd
clock.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
PROJECT: DIGITAL CLOCK
AUTHOR: WOUTER DE SCHUYTER
[email protected]
HTTP://PARADOX-PRODUCTIONS.NET
DATE: 16-07-2009
*/
/* CONFIG
*********/
// WIDTH
$width = 84;
// HEIGHT
$height = 24;
// RANDOM TEXT COLORS? (true = YES, background will be black)
$randomcolors = true;
// COLORS (WILL BE DISABLED IF RANDOM COLOR IS SET TO TRUE)
// AVAIABLE COLORS: "LIME", "RED", "WHITE", "GRAY", "BLUE", "CYAN", "PINK", "VIOLET", "GREEN", "BLACK"
$fontcolor = "VIOLET"; // FONT
$bgcolor = "BLACK"; // BACKGROUND
// FONT LOCATION
$fontloc = "clockfont.ttf";
/* - - - - - - END CONFIG - - - - - - */
header("Content-type: image/png");
// CREATE IMAGE
$img = imagecreate($width, $height);
// TIME
$time = date("H:i:s");
// SET COLORS
$color = array(
"WHITE" => imagecolorallocate($img, 255, 255, 255),
"BLACK" => imagecolorallocate($img, 0, 0, 0),
"GRAY" => imagecolorallocate($img, 192, 192, 192),
"RED" => imagecolorallocate($img, 255, 0, 0),
"BLUE" => imagecolorallocate($img, 0, 0, 255),
"PINK" => imagecolorallocate($img, 255, 0, 135),
"VIOLET" => imagecolorallocate($img, 239, 0, 234),
"CYAN" => imagecolorallocate($img, 15, 235, 255),
"LIME" => imagecolorallocate($img, 0, 255, 0),
"GREEN" => imagecolorallocate($img, 60, 190, 60)
);
$colornames = array("WHITE", "GRAY", "RED", "BLUE", "PINK", "VIOLET", "CYAN", "LIME", "GREEN");
// RANDOM COLORS?
if($randomcolors == true) {
// DRAW BACKGROUND
imagefilltoborder($img, $width, $height, 1, $color["BLACK"]);
// DRAW TIME
imagefttext($img, 20, 0, 2, 20, $color[$colornames[rand(0, 8)]], $fontloc, $time);
}
// USE CONFIG SETTINGS
else {
// DRAW BACKGROUND
imagefilltoborder($img, $width, $height, 1, $color[strtoupper($bgcolor)]);
// DRAW TIME
imagefttext($img, 20, 0, 2, 20, $color[strtoupper($fontcolor)], $fontloc, $time);
}
imagepng($img);
imagedestroy($img);
?>
/*
PROJECT: DIGITAL CLOCK
AUTHOR: WOUTER DE SCHUYTER
[email protected]
HTTP://PARADOX-PRODUCTIONS.NET
DATE: 16-07-2009
*/
/* CONFIG
*********/
// WIDTH
$width = 84;
// HEIGHT
$height = 24;
// RANDOM TEXT COLORS? (true = YES, background will be black)
$randomcolors = true;
// COLORS (WILL BE DISABLED IF RANDOM COLOR IS SET TO TRUE)
// AVAIABLE COLORS: "LIME", "RED", "WHITE", "GRAY", "BLUE", "CYAN", "PINK", "VIOLET", "GREEN", "BLACK"
$fontcolor = "VIOLET"; // FONT
$bgcolor = "BLACK"; // BACKGROUND
// FONT LOCATION
$fontloc = "clockfont.ttf";
/* - - - - - - END CONFIG - - - - - - */
header("Content-type: image/png");
// CREATE IMAGE
$img = imagecreate($width, $height);
// TIME
$time = date("H:i:s");
// SET COLORS
$color = array(
"WHITE" => imagecolorallocate($img, 255, 255, 255),
"BLACK" => imagecolorallocate($img, 0, 0, 0),
"GRAY" => imagecolorallocate($img, 192, 192, 192),
"RED" => imagecolorallocate($img, 255, 0, 0),
"BLUE" => imagecolorallocate($img, 0, 0, 255),
"PINK" => imagecolorallocate($img, 255, 0, 135),
"VIOLET" => imagecolorallocate($img, 239, 0, 234),
"CYAN" => imagecolorallocate($img, 15, 235, 255),
"LIME" => imagecolorallocate($img, 0, 255, 0),
"GREEN" => imagecolorallocate($img, 60, 190, 60)
);
$colornames = array("WHITE", "GRAY", "RED", "BLUE", "PINK", "VIOLET", "CYAN", "LIME", "GREEN");
// RANDOM COLORS?
if($randomcolors == true) {
// DRAW BACKGROUND
imagefilltoborder($img, $width, $height, 1, $color["BLACK"]);
// DRAW TIME
imagefttext($img, 20, 0, 2, 20, $color[$colornames[rand(0, 8)]], $fontloc, $time);
}
// USE CONFIG SETTINGS
else {
// DRAW BACKGROUND
imagefilltoborder($img, $width, $height, 1, $color[strtoupper($bgcolor)]);
// DRAW TIME
imagefttext($img, 20, 0, 2, 20, $color[strtoupper($fontcolor)], $fontloc, $time);
}
imagepng($img);
imagedestroy($img);
?>
clock.html
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<!--
PROJECT: DIGITAL CLOCK
AUTHOR: WOUTER DE SCHUYTER
[email protected]
HTTP://PARADOX-PRODUCTIONS.NET
DATE: 16-07-2009
-->
<head>
<script type="text/javascript">
// RELOAD IMAGE EVERY SECOND
setInterval("document.getElementById('clock').src = document.getElementById('clock').src + '?' + (new Date()).getTime();", 1000);
</script>
<title>Clock</title>
</head>
<body>
Clock<br />
<img src="clock.php" alt="clock" />
<br /><br />
Reload Clock With JS<br />
<img id="clock" src="clock.php" alt="ajax clock" />
</body>
</html>
<!--
PROJECT: DIGITAL CLOCK
AUTHOR: WOUTER DE SCHUYTER
[email protected]
HTTP://PARADOX-PRODUCTIONS.NET
DATE: 16-07-2009
-->
<head>
<script type="text/javascript">
// RELOAD IMAGE EVERY SECOND
setInterval("document.getElementById('clock').src = document.getElementById('clock').src + '?' + (new Date()).getTime();", 1000);
</script>
<title>Clock</title>
</head>
<body>
Clock<br />
<img src="clock.php" alt="clock" />
<br /><br />
Reload Clock With JS<br />
<img id="clock" src="clock.php" alt="ajax clock" />
</body>
</html>
--