Browse code

Fix GD captcha fonts path for PHP 8.6 and GD 2.4.0 library users

Clarissa Walker authored on 2026/09/04 13:58:06
Showing 1 changed files
... ...
@@ -31,14 +31,17 @@ return $color;
31 31
 
32 32
 putenv('GDFONTPATH=' . realpath('.'));
33 33
 
34
-$folder=dir("cFonts/"); //The directory where your fonts reside
35
-
36 34
 while($font=$folder->read()) {
37
-  if(stristr($font,'.ttf')) $fontList[] = "cFonts/".$font;
35
+if(stristr($font,'.ttf')) {
36
+  // Check GD Version 2.4.0 or later
37
+  if (version_compare(GD_VERSION, '2.4.0', '>=')) {
38
+    $fontList[] = "cFonts/".str_replace(".ttf", "", $font);
39
+    } else {
40
+    $fontList[] = "cFonts/".$font;
41
+    }
42
+  }
38 43
 }
39 44
 
40
-$folder->close();
41
-
42 45
 for ($i = 0; $i < 5; $i++) {
43 46
 $cnum[$i] = rand(0,9);
44 47
 $rC = rgb_rand(0, 175);
... ...
@@ -63,7 +66,6 @@ for ($i = 0; $i < 5; $i++) {
63 66
  $x = $x + mt_rand(16, 24);
64 67
  $y = mt_rand(26, 32); 
65 68
  $angle = mt_rand(-15, 15);
66
- $c = $color[$i];
67 69
  $fnt = mt_rand(0, sizeof($fontList) - 1);
68 70
  $colori = $rColors[$i];
69 71
  imagettftext($image, mt_rand(20, 24), $angle,  $x, $y, $colori, $fontList[$fnt], $cnum[$i]); 
... ...
@@ -85,4 +87,3 @@ imagedestroy($image);
85 87
 
86 88
 exit( );
87 89
 ?> 
88
-