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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
<?php
// TTF-Schrift
// Sie sollten hier unbedingt den absoluten Pfad angeben, da ansonsten
// eventuell die TTF-Datei nicht eingebunden werden kann!
$fileTTF = 'http://htdocs/XXXXXXXX/test/bilder/MTCORSVA.TTF';
// Verzeichnis für die Captcha-Bilder (muss Schreibrechte besitzen!)
// Ausserdem sollten in diesem Ordner nur die Bilder gespeichert werden
// da das Programm in regelmaessigen Abstaenden dieses leert!
// Kein abschliessenden Slash benutzen!
$captchaDir = 'http://htdocs/XXXXXXXX/test/captcha/captchadir';
// Schriftgröße
$size = 30;
//Bildgroesse
$imgWidth = 209;//200
$imgHeight = 80;//80
$im = @imagecreate($imgWidth, $imgHeight)
// Farbverlauf RGB-Wert Start und RGB-Wert Ende
$fromRGB = array( ********************
253,
214,
0
);
$toRGB = array(
215,
81,
6
);
// Erstellt den Farbverlauf
$colorRGB = makeGradient($fromRGB,$toRGB,$imgHeight);
function makeGradient($fromRGB,$toRGB,$imgHeight){
$diffR = ($fromRGB[0]-$toRGB[0]); //38
$diffG = ($fromRGB[1]-$toRGB[1]); //133
$diffB = ($fromRGB[2]-$toRGB[2]); // -6
$maxR = $diffR / $imgHeight; // 0.475
$maxG = $diffG / $imgHeight; // 1,66
$maxB = $diffB / $imgHeight; // 0.075
$maxNR = $maxR;
$maxNG = $maxG;
$maxNB = $maxB;
for($x=0;$x<$imgHeight;$x++){
$color['r'][$x] = abs($fromRGB[0] - $maxR);
$color['g'][$x] = abs($fromRGB[1] - $maxG);
$color['b'][$x] = abs($fromRGB[2] - $maxB);
$maxR += $maxNR;
$maxG += $maxNG;
$maxB += $maxNB;
}
return $color;
}
// Randfarbe
$colorBorder = array(
154,
53,
2
);
// Border erstellen
makeBorder($im,$imgWidth,$imgHeight,$colorB);
function makeBorder($imgWidth,$imgHeight,$im,$color){
imageline($im,0,0,$imgWidth,0,$color);
imageline($im,0,$imgHeight-1,$imgWidth,$imgHeight-1,$color);
imageline($im,0,0,0,$imgHeight,$color);
imageline($im,$imgWidth-1,0,$imgWidth-1,$imgHeight,$color);
}
//Wortliste erstellen
$alphabet = MakeAlphabet();
// Array des Alphabets durchwürfeln
shuffle($alphabet);
$mix = range(0,255);
shuffle($mix);
function MakeAlphabet(){
// Grossbuchstaben erzeugen
for ($x = 65; $x <= 90; $x++) {
if($x != 73 && $x != 76 && $x != 79)
$alphabet[] = chr($x);
}
// Kleinbuchstaben erzeugen
for ($x = 97; $x <= 122; $x++) {
if($x != 105 && $x != 108 && $x != 111)
$alphabet[] = chr($x);
}
// Zahlen erzeugen
for ($x = 48; $x <= 57; $x++) {
if($x != 48 && $x != 49)
$alphabet[] = chr($x);
}
return $alphabet;
}
$colors=array(
imagecolorallocate($im,$mix[0],$mix[6],$mix[12]),
imagecolorallocate($im,$mix[1],$mix[7],$mix[13]),
imagecolorallocate($im,$mix[2],$mix[8],$mix[14]),
imagecolorallocate($im,$mix[3],$mix[9],$mix[15]),
imagecolorallocate($im,$mix[4],$mix[10],$mix[16]),
imagecolorallocate($im,$mix[5],$mix[11],$mix[17])
);
// Zeichnet die Buchstaben und baut den Dateinamen auf
for($x=0;$x<6;$x++){
$angel = rand(-25,25);
$y = rand($size,$imgHeight-20);
imagettftext($im, $size, $angel, $next, $y, $colors[$x], $fileTTF,$alphabet[$x]);
$next += $size + ($imgWidth/$size);
$fileName .= $alphabet[$x];
}
// Uebermittelter Hash-Wert ueberpruefen
if(!preg_match('/^[a-f0-9]{32}$/',$_GET['codeCaptcha']))
$_GET['codeCaptcha'] = md5(microtime());
// Image speichern
imagepng($im,$captchaDir.'/'.$_GET['codeCaptcha'].'_'.$fileName.'.png');
imagedestroy($im);
// Bild ausgeben
readfile($captchaDir.'/'.$_GET['codeCaptcha'].'_'.$fileName.'.png');
header("Content-type: image/png");
$im = @imagecreate($imgWidth, $imgHeight) or die("GD! Initialisierung fehlgeschlagen");
// Definiert die Farbe für den Border
$colorB = imagecolorallocate($im,$colorBorder[0],$colorBorder[1],$colorBorder[2]);
// Erstellt den Farbverlauf
$colorRGB = makeGradient($fromRGB,$toRGB,$imgHeight);
for($x=0;$x<$imgHeight;$x++){
$r = $colorRGB['r'][$x];
$g = $colorRGB['g'][$x];
$b = $colorRGB['b'][$x];
$color = imagecolorallocate($im,$r,$g,$b);
imageline($im,0,$x,$imgWidth,$x,$color);
}
?>
|