) - the ’fontfile’ parameter MUST include the absolute path along with the filename! If you only supply a relative path, the function will find the font file but for some reason it will return an array filled with ZEROS!while ($file = $dir->read()) {
if(strstr($file,'.ttf') ) { // include only .ttf files
$fontstmp[] = $this->dir_font.'/'.$file;
}
}// prefix font file name with absolute path $text_font = dirname($_SERVER['DOCUMENT_ROOT'].$_SERVER['SCRIPT_NAME']). '/ttf/' . $text_font;
Your modified veriword file solved my problem too!I had no problem with the zip; strange. Anyway, here is a patch of his changes, so as not to paste the whole thing:
Could someone please paste the modified veriword code into a message here. The .zip file is empty for me no matter how I access it, and I have no clue what’s been done to veriword.php.
Index: manager/includes/veriword.php =================================================================== --- manager/includes/veriword.php (revision 4060) +++ manager/includes/veriword.php (working copy) @@ -1,4 +1,12 @@ <?php +// Date: Monday, September 1, 2008 @ 1:57pm EST +// modified version: bug found if file hosted on Windows-based server +// issue: imagettftext() requires absolute path to font file or it DOES NOT work +// The only modified code is in member function draw_text() in this file. +// +// Author: Jeff Chown ([email protected]) + + include_once("config.inc.php"); $vword = new VeriWord(148,60); @@ -77,7 +85,7 @@ // connect to the database if(@$dbConn = mysql_connect($database_server, $database_user, $database_password)) { mysql_select_db($dbase); - @mysql_query("{$database_connection_method} {$database_connection_charset}"); + @mysql_query("SET CHARACTER SET {$database_connection_charset}"); $sql = "SELECT * FROM $dbase.`".$table_prefix."system_settings` WHERE setting_name='captcha_words'"; $rs = mysql_query($sql); $limit = mysql_num_rows($rs); @@ -108,6 +116,7 @@ /* pick one font type randomly from font directory */ //$text_font = $this->dir_font."".rand(1,3).".ttf"; // added by Alex - read ttf dir +/* $dir = dir("./ttf"); $fontstmp = array(); while (false !== ($file = $dir->read())) { @@ -117,6 +126,25 @@ } $dir->close(); $text_font = (string) $fontstmp[array_rand($fontstmp)]; +*/ + + // added by Jeff Chown ([email protected]) - Sept. 1/08 to resolve issue with relative path + // on Windows servers - essentially a duplicate of Alex's above block with + // adjustments for absolute path in font file name + $dir = dir("./ttf"); + $fontstmp = array(); + while (false !== ($file = $dir->read())) { + if($file!="." && $file!=".." && file_exists('./ttf/'.$file) && !is_dir('./ttf/' . $file)) { + $fontstmp[] = $file; // just the file name, no path yet + } + } + $dir->close(); + + $text_font = (string) $fontstmp[array_rand($fontstmp)]; + // prefix font file name with absolute path + $text_font = dirname($_SERVER['DOCUMENT_ROOT'].$_SERVER['SCRIPT_NAME']). '/ttf/' . $text_font; + // + // end of modifications /* angle for text inclination */ $text_angle = rand(-9,9);
Index: manager/includes/veriword.php
===================================================================
--- manager/includes/veriword.php (revision 4064)
+++ manager/includes/veriword.php (working copy)
@@ -40,7 +40,7 @@
class VeriWord {
/* path to font directory*/
- var $dir_font = "fonts/";
+ var $dir_font = "ttf/";
/* path to background image directory*/
var $dir_noise = "noises/";
var $word = "";
@@ -50,7 +50,8 @@
function VeriWord($w=200, $h=80) {
/* create session to set word for verification */
startCMSSession();
- $this->set_veriword();
+ $this->set_veriword();
+ $this->dir_font = dirname(__FILE__) . '/' . $this->dir_font;
$this->im_width = $w;
$this->im_height = $h;
}
@@ -105,14 +106,11 @@
}
}
- /* pick one font type randomly from font directory */
- //$text_font = $this->dir_font."".rand(1,3).".ttf";
- // added by Alex - read ttf dir
- $dir = dir("./ttf");
+ $dir = dir($this->dir_font);
$fontstmp = array();
while (false !== ($file = $dir->read())) {
- if($file!="." && $file!=".." && file_exists('./ttf/'.$file) && !is_dir('./ttf/' . $file)) {
- $fontstmp[] = './ttf/'.$file;
+ if($file!="." && $file!=".." && file_exists($this->dir_font.$file) && !is_dir($this->dir_font . $file)) {
+ $fontstmp[] = $this->dir_font.$file;
}
}
$dir->close();
while ($file = $dir->read()) {
if(strstr($file,'.ttf') ) { // include only .ttf files
$fontstmp[] = $this->dir_font.'/'.$file;
}
}Index: manager/includes/veriword.php
===================================================================
--- manager/includes/veriword.php (revision 4064)
+++ manager/includes/veriword.php (working copy)
@@ -40,7 +40,7 @@
class VeriWord {
/* path to font directory*/
- var $dir_font = "fonts/";
+ var $dir_font = "ttf/";
/* path to background image directory*/
var $dir_noise = "noises/";
var $word = "";
@@ -50,7 +50,8 @@
function VeriWord($w=200, $h=80) {
/* create session to set word for verification */
startCMSSession();
- $this->set_veriword();
+ $this->set_veriword();
+ $this->dir_font = dirname(__FILE__) . '/' . $this->dir_font;
$this->im_width = $w;
$this->im_height = $h;
}
@@ -105,14 +106,11 @@
}
}
- /* pick one font type randomly from font directory */
- //$text_font = $this->dir_font."".rand(1,3).".ttf";
- // added by Alex - read ttf dir
- $dir = dir("./ttf");
+ $dir = dir($this->dir_font);
$fontstmp = array();
while (false !== ($file = $dir->read())) {
- if($file!="." && $file!=".." && file_exists('./ttf/'.$file) && !is_dir('./ttf/' . $file)) {
- $fontstmp[] = './ttf/'.$file;
+ if(strstr($file, '.ttf')) {
+ $fontstmp[] = $this->dir_font.$file;
}
}
$dir->close();