simpele-counter-met-gd-en-ttf-zonder-sql
Gesponsorde koppelingen
PHP script bestanden
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
$conf["file"] = "counter.dat"; //filename for storing
$conf["length"] = 6; //digits in counter
$conf["imageheight"] = 50; //height
$conf["automaticwidth"] = TRUE;
$conf["imagewidth"] = 144; //width
$conf["bgcolor"] = "000000"; //background color (hex)
$conf["fgcolor"] = "FFFFFF"; //foreground color (hex)
$conf["textalign"] = "center"; //left, center or right
$conf["TTFfilename"] = "./arialbd.ttf"; //TTF file (hint: C:\Windows\Fonts)
$conf["TTFsize"] = 12; //size in points
$conf["TTFangle"] = 0; //angle of text
/**************************************/
clearstatcache();
if(file_exists($conf["file"]) && is_readable($conf["file"]))
{
$array = file($conf["file"]);
$count = $array["0"];
}
$count++;
$fp = fopen($conf["file"], "w");
fwrite($fp, $count);
fclose($fp);
$text = str_repeat("0", $conf["length"]);
$text = substr_replace($text, $count, -(strlen($count)));
$text = substr($text, -($conf["length"]));
$size = ImageTTFBBox($conf["TTFsize"], $conf["angle"], $conf["TTFfilename"], $text);
$textwidth = ($size["2"] - $size["0"]);
$textheight = ($size["5"] - $size["3"]);
$conf["imagewidth"] = ($conf["automaticwidth"] == TRUE) ? ($textwidth + 6) : $conf["imagewidth"];
switch($conf["textalign"])
{
case "left":
$textleft = 0;
break;
case "center":
$textleft = (($conf["imagewidth"] - $textwidth) / 2);
break;
case "right":
$textleft = ($conf["imagewidth"] - $textwidth);
break;
}
$textbottom = (($conf["imageheight"] - $textheight) / 2);
$img = ImageCreate($conf["imagewidth"], $conf["imageheight"]);
$bgred = hexdec(substr($conf["bgcolor"], 0, 2));
$bggreen = hexdec(substr($conf["bgcolor"], 2, 2));
$bgblue = hexdec(substr($conf["bgcolor"], 4, 2));
$bgcolor = ImageColorAllocate($img, $bgred, $bggreen, $bgblue);
$fgred = hexdec(substr($conf["fgcolor"], 0, 2));
$fggreen = hexdec(substr($conf["fgcolor"], 2, 2));
$fgblue = hexdec(substr($conf["fgcolor"], 4, 2));
$fgcolor = ImageColorAllocate($img, $fgred, $fggreen, $fgblue);
ImageFilledRectangle($img, 0, 0, $conf["imagewidth"], $conf["imageheight"], $bgcolor);
ImageTTFText($img, $conf["TTFsize"], $conf["TTFangle"], $textleft, $textbottom, $fgcolor, $conf["TTFfilename"], $text);
header('Content-type: image/png');
imagepng($img);
ImageDestroy($img);
?>
$conf["file"] = "counter.dat"; //filename for storing
$conf["length"] = 6; //digits in counter
$conf["imageheight"] = 50; //height
$conf["automaticwidth"] = TRUE;
$conf["imagewidth"] = 144; //width
$conf["bgcolor"] = "000000"; //background color (hex)
$conf["fgcolor"] = "FFFFFF"; //foreground color (hex)
$conf["textalign"] = "center"; //left, center or right
$conf["TTFfilename"] = "./arialbd.ttf"; //TTF file (hint: C:\Windows\Fonts)
$conf["TTFsize"] = 12; //size in points
$conf["TTFangle"] = 0; //angle of text
/**************************************/
clearstatcache();
if(file_exists($conf["file"]) && is_readable($conf["file"]))
{
$array = file($conf["file"]);
$count = $array["0"];
}
$count++;
$fp = fopen($conf["file"], "w");
fwrite($fp, $count);
fclose($fp);
$text = str_repeat("0", $conf["length"]);
$text = substr_replace($text, $count, -(strlen($count)));
$text = substr($text, -($conf["length"]));
$size = ImageTTFBBox($conf["TTFsize"], $conf["angle"], $conf["TTFfilename"], $text);
$textwidth = ($size["2"] - $size["0"]);
$textheight = ($size["5"] - $size["3"]);
$conf["imagewidth"] = ($conf["automaticwidth"] == TRUE) ? ($textwidth + 6) : $conf["imagewidth"];
switch($conf["textalign"])
{
case "left":
$textleft = 0;
break;
case "center":
$textleft = (($conf["imagewidth"] - $textwidth) / 2);
break;
case "right":
$textleft = ($conf["imagewidth"] - $textwidth);
break;
}
$textbottom = (($conf["imageheight"] - $textheight) / 2);
$img = ImageCreate($conf["imagewidth"], $conf["imageheight"]);
$bgred = hexdec(substr($conf["bgcolor"], 0, 2));
$bggreen = hexdec(substr($conf["bgcolor"], 2, 2));
$bgblue = hexdec(substr($conf["bgcolor"], 4, 2));
$bgcolor = ImageColorAllocate($img, $bgred, $bggreen, $bgblue);
$fgred = hexdec(substr($conf["fgcolor"], 0, 2));
$fggreen = hexdec(substr($conf["fgcolor"], 2, 2));
$fgblue = hexdec(substr($conf["fgcolor"], 4, 2));
$fgcolor = ImageColorAllocate($img, $fgred, $fggreen, $fgblue);
ImageFilledRectangle($img, 0, 0, $conf["imagewidth"], $conf["imageheight"], $bgcolor);
ImageTTFText($img, $conf["TTFsize"], $conf["TTFangle"], $textleft, $textbottom, $fgcolor, $conf["TTFfilename"], $text);
header('Content-type: image/png');
imagepng($img);
ImageDestroy($img);
?>