Browse code

Resize GD captcha for today's resolutions - and add forgotten set font directory

Clarissa Walker authored on 2026/09/04 14:38:39
Showing 3 changed files
... ...
@@ -8,7 +8,7 @@ define("_BASEDIR", "../");
8 8
 include("../config.php");
9 9
 unset($_SESSION[$sitekey.'_digit']);
10 10
 
11
-$image = imagecreate(140, 40);
11
+$image = imagecreate(280, 80);
12 12
 
13 13
 $white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
14 14
 $gray    = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
... ...
@@ -31,6 +31,8 @@ return $color;
31 31
 
32 32
 putenv('GDFONTPATH=' . realpath('.'));
33 33
 
34
+$folder=dir("cFonts/"); //The directory where your fonts reside
35
+
34 36
 while($font=$folder->read()) {
35 37
 if(stristr($font,'.ttf')) {
36 38
   // Check GD Version 2.4.0 or later
... ...
@@ -48,27 +50,27 @@ $rC = rgb_rand(0, 175);
48 50
 $rColors[$i] = imagecolorallocate($image, $rC['r'], $rC['g'], $rC['b']);
49 51
 
50 52
 for ($x = 0; $x < 2; $x++) {
51
-  $x1 = rand(0,140);
52
-  $y1 = rand(0,40);
53
-  $x2 = rand(0,140);
54
-  $y2 = rand(0,40);
53
+  $x1 = rand(0,280);
54
+  $y1 = rand(0,80);
55
+  $x2 = rand(0,280);
56
+  $y2 = rand(0,80);
55 57
   imageline($image, $x1, $y1, $x2, $y2 , $rColors[$i]);  
56 58
 }
57 59
 
58 60
 }
59 61
 
60 62
 /* generate random dots in background */
61
-for( $i=0; $i<(140*40)/3; $i++ ) {
62
-  imagefilledellipse($image, mt_rand(0,140), mt_rand(0,40), 1, 1, $gray);
63
+for( $i=0; $i<(280*80)/3; $i++ ) {
64
+  imagefilledellipse($image, mt_rand(0,280), mt_rand(0,80), 1, 1, $gray);
63 65
 }
64 66
 
65 67
 for ($i = 0; $i < 5; $i++) {
66
- $x = $x + mt_rand(16, 24);
67
- $y = mt_rand(26, 32); 
68
- $angle = mt_rand(-15, 15);
68
+ $x = $x + mt_rand(32, 48);
69
+ $y = mt_rand(52, 64);
70
+ $angle = mt_rand(-30, 30);
69 71
  $fnt = mt_rand(0, sizeof($fontList) - 1);
70 72
  $colori = $rColors[$i];
71
- imagettftext($image, mt_rand(20, 24), $angle,  $x, $y, $colori, $fontList[$fnt], $cnum[$i]); 
73
+ imagettftext($image, mt_rand(40, 48), $angle, $x, $y, $colori, $fontList[$fnt], $cnum[$i]);
72 74
 
73 75
 }
74 76
  
... ...
@@ -48,9 +48,9 @@ if($ratings == "1") {
48 48
 	}
49 49
 	$form .= "<option value=\"-1\"".($review['rating'] == -1 || $action != "edit" ? " selected" : "").">"._NONE."</option></select></div>";
50 50
 }
51
-if(!USERUID && !empty($captcha)) $form .= "<div><span class=\"label\">"._CAPTCHANOTE."</span><input MAXLENGTH=5 SIZE=5 name=\"userdigit\" type=\"text\" value=\"\"><br /><img width=120 height=30 src=\""._BASEDIR."includes/button.php\" style=\"border: 1px solid #111;\"></div>";
51
+if(!USERUID && !empty($captcha)) $form .= "<div><span class=\"label\">"._CAPTCHANOTE."</span><input MAXLENGTH=5 SIZE=5 name=\"userdigit\" type=\"text\" value=\"\"><br /><img width=240 height=60 src=\""._BASEDIR."includes/button.php\" style=\"border: 1px solid #111;\"></div>";
52 52
 
53 53
 $form .= "<INPUT type=\"hidden\" name=\"chapid\" value=\"".(isset($chapid) ? $chapid : "")."\"><div style=\"text-align: center; margin: 1ex;\"><INPUT type=\"submit\" class=\"button\" name=\"submit\" value=\""._SUBMIT."\"></div>";
54 54
 if(!empty($rateonly)) $form .= "<div>"._REVIEWNOTE."</div>";
55 55
 $form .= "</div></form>";
56
-?>
57 56
\ No newline at end of file
57
+?>
... ...
@@ -239,7 +239,7 @@ function random_string ($charset_string, $length)
239 239
 		if($action != "register" || $pwdsetting)
240 240
 	 	$output .= "<div><label for='password'>"._PASSWORD.":</label>  <INPUT name=\"password\" class=\"textbox\" value=\"\" type=\"password\">".($action == "register" ? "<font color=\"red\">*</font>" : "")."</div>
241 241
 			<div><label for='password2'>"._PASSWORD2.":</label> <INPUT name=\"password2\" class=\"textbox=\" value=\"\" type=\"password\">".($action == "register" ? "<font color=\"red\">*</font>" : "")."</div>";
242
-		if(!empty($captcha) && $action == "register") $output .= "<div><label for='userdigit'>"._CAPTCHANOTE."</label><input MAXLENGTH=5 SIZE=5 name=\"userdigit\" type=\"text\" value=\"\"><div style='text-align: center;'><img width=120 height=30 src=\""._BASEDIR."includes/button.php\" style=\"border: 1px solid #111;\"></div></div>";
242
+		if(!empty($captcha) && $action == "register") $output .= "<div><label for='userdigit'>"._CAPTCHANOTE."</label><input MAXLENGTH=5 SIZE=5 name=\"userdigit\" type=\"text\" value=\"\"><div style='text-align: center;'><img width=240 height=60 src=\""._BASEDIR."includes/button.php\" style=\"border: 1px solid #111;\"></div></div>";
243 243
 	 	$output .= "<div style='text-align: center; margin: 1em;'><INPUT type=\"hidden\" name=\"uid\" value=\"".(isset($user) ? $user['uid'] : "")."\"><INPUT type=\"submit\" class=\"button\" name=\"submit\" value=\""._SUBMIT."\">";
244 244
 	 	if(!isADMIN && $action != "register")
245 245
 	 	{