43 |
43 |
list($usec, $sec) = explode(' ', microtime());
|
44 |
44 |
srand((float)$sec + ((float)$usec * 100000));
|
45 |
45 |
//$possible="ABCDEFGHJKLMNPRSTUVWXYZabcdefghkmnpqrstuvwxyz23456789";
|
46 |
|
$possible="abdfhkrsvwxyz23456789";
|
|
46 |
$possible="abdfhkrsvwxz23456789";
|
47 |
47 |
$str="";
|
48 |
48 |
while(strlen($str)<$len) {
|
49 |
49 |
$str.=substr($possible,(rand()%(strlen($possible))),1);
|
... | ... | |
61 |
61 |
list($width, $height, $type, $attr) = getimagesize($bg);
|
62 |
62 |
|
63 |
63 |
// create image
|
64 |
|
$image_failed = true;
|
65 |
|
$i=0;
|
66 |
|
do {
|
67 |
|
$image = ImageCreateFromPNG($bg); // backgroundimage
|
68 |
|
$grey = rand(0,50);
|
69 |
|
$color = ImageColorAllocate($image, $grey, $grey, $grey); // Farbe
|
70 |
|
$ttf = $font;
|
71 |
|
$ttfsize = 25; // fontsize
|
72 |
|
$angle = rand(0,5);
|
73 |
|
$t_x = rand(5,30);
|
74 |
|
$t_y = rand($height-10,$height-2);
|
75 |
|
$res = imagettftext($image, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text);
|
76 |
|
// check if text fits into the image
|
77 |
|
if(($res[0]>0 && $res[0]<$width) && ($res[1]>0 && $res[1]<$height) &&
|
78 |
|
($res[2]>0 && $res[2]<$width) && ($res[3]>0 && $res[3]<$height) &&
|
79 |
|
($res[4]>0 && $res[4]<$width) && ($res[5]>0 && $res[5]<$height) &&
|
80 |
|
($res[6]>0 && $res[6]<$width) && ($res[7]>0 && $res[7]<$height)
|
81 |
|
) {
|
82 |
|
$image_failed = false;
|
83 |
|
}
|
84 |
|
if(++$i > 5) // too many tries! Use the image
|
85 |
|
break;
|
86 |
|
} while($image_failed);
|
87 |
64 |
|
|
65 |
$image = ImageCreateFromPNG($bg); // background image
|
|
66 |
$grey = rand(0,50);
|
|
67 |
$color = ImageColorAllocate($image, $grey, $grey, $grey); // font-color
|
|
68 |
$ttf = $font;
|
|
69 |
$ttfsize = 25; // fontsize
|
|
70 |
$angle = rand(-15,15);
|
|
71 |
$x = rand(10,25);
|
|
72 |
$y = rand($height-10,$height-2);
|
|
73 |
|
|
74 |
if(rand(0,2)==0) { // 1 out of 3
|
|
75 |
|
|
76 |
// draw each character individualy
|
|
77 |
$count = 0;
|
|
78 |
$image_failed = true;
|
|
79 |
do {
|
|
80 |
for($i=0;$i<5;$i++) {
|
|
81 |
$res = imagettftext($image, $ttfsize, $angle, $x, $y, $color, $ttf, $text{$i});
|
|
82 |
$angle = rand(-15,15);
|
|
83 |
$x = rand($res[4],$res[4]+10);
|
|
84 |
$y = rand($height-15,$height-5);
|
|
85 |
}
|
|
86 |
if($res[4] > $width) {
|
|
87 |
$image_failed = true;
|
|
88 |
} else {
|
|
89 |
$image_failed = false;
|
|
90 |
}
|
|
91 |
if(++$count > 4) // too many tries! Use the image
|
|
92 |
break;
|
|
93 |
} while($image_failed);
|
|
94 |
|
|
95 |
} else {
|
|
96 |
|
|
97 |
// draw whole string at once
|
|
98 |
$image_failed = true;
|
|
99 |
$count=0;
|
|
100 |
do {
|
|
101 |
$image = ImageCreateFromPNG($bg); // background image
|
|
102 |
$grey = rand(0,50);
|
|
103 |
$color = ImageColorAllocate($image, $grey, $grey, $grey); // font-color
|
|
104 |
$ttf = $font;
|
|
105 |
$ttfsize = 25; // fontsize
|
|
106 |
$angle = rand(0,5);
|
|
107 |
$t_x = rand(5,30);
|
|
108 |
$t_y = rand($height-10,$height-2);
|
|
109 |
$res = imagettftext($image, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $text);
|
|
110 |
// check if text fits into the image
|
|
111 |
if(($res[0]>0 && $res[0]<$width) && ($res[1]>0 && $res[1]<$height) &&
|
|
112 |
($res[2]>0 && $res[2]<$width) && ($res[3]>0 && $res[3]<$height) &&
|
|
113 |
($res[4]>0 && $res[4]<$width) && ($res[5]>0 && $res[5]<$height) &&
|
|
114 |
($res[6]>0 && $res[6]<$width) && ($res[7]>0 && $res[7]<$height)
|
|
115 |
) {
|
|
116 |
$image_failed = false;
|
|
117 |
}
|
|
118 |
if(++$count > 5) // too many tries! Use the image
|
|
119 |
break;
|
|
120 |
} while($image_failed);
|
|
121 |
|
|
122 |
}
|
|
123 |
|
88 |
124 |
captcha_header();
|
89 |
125 |
ob_start();
|
90 |
126 |
imagepng($image);
|
CAPTCHA ttf_image: added variant. Adjusted character-pool and one background for better readability.