jrp91384 Posted November 12, 2009 Share Posted November 12, 2009 Help Please! I’m receiving the following error. Warning: imagettftext() [function.imagettftext]: Invalid font filename in /home/xxx/public_html/wp-content/plugins/mm-forms/captcha/captcha.php on line 60 I have checked and the folder and files needed are writable. I also contacted my host to see if Truetype was on the server and it is. What else could be causing this? Any help would be greatly appreciated!! Thank you Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/ Share on other sites More sharing options...
MadTechie Posted November 12, 2009 Share Posted November 12, 2009 the font used in imagettftext can't be found or doesn't exists, goto line 60 of captcha.php and check the 7th parameter to check the name (it maybe missing .ttf), or update to another font Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956518 Share on other sites More sharing options...
jrp91384 Posted November 13, 2009 Author Share Posted November 13, 2009 the font used in imagettftext can't be found or doesn't exists, goto line 60 of captcha.php and check the 7th parameter to check the name (it maybe missing .ttf), or update to another font Hi MadTechie I'm not mr. php but the files and paths look correct. Below is the code i have and the ttf files are in a file called gentium. Something strange is one of the fonts in that file is showing. Not sure what font it is but when you refresh the page it changes the captcha image and shows 1 letter sometimes and 2-3 letters another time. Any Ideas?? Thanks for the help!!!! this is line 60 imagettftext($im, $this->font_size, mt_rand(-2, 2), $x, $this->base[1] + mt_rand(-2, 2), $fg, $font, $captcha[$i]); class mm_captcha { function mm_captcha() { $this->chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; $this->char_length = 4; $this->fonts = array( dirname(__FILE__) . '/gentium/GenAI102.TTF', dirname(__FILE__) . '/gentium/GenAR102.TTF', dirname(__FILE__) . '/gentium/GenI102.TTF', dirname(__FILE__) . '/gentium/GenR102.TTF'); $this->tmp_dir = dirname(__FILE__) . '/tmp/'; $this->img_size = array(72, 24); $this->bg = array(255, 255, 255); $this->fg = array(0, 0, 0); $this->base = array(6, 18); $this->font_size = 14; $this->font_char_width = 15; $this->img_type = 'png'; } function generate_random_word() { $word = ''; for ($i = 0; $i < $this->char_length; $i++) { $pos = mt_rand(0, strlen($this->chars) - 1); $char = $this->chars[$pos]; $word .= $char; } return $word; } function generate_image($prefix, $captcha) { $filename = null; if ($im = imagecreatetruecolor($this->img_size[0], $this->img_size[1])) { $bg = imagecolorallocate($im, $this->bg[0], $this->bg[1], $this->bg[2]); $fg = imagecolorallocate($im, $this->fg[0], $this->fg[1], $this->fg[2]); imagefill($im, 0, 0, $bg); $x = $this->base[0] + mt_rand(-2, 2); for ($i = 0; $i < strlen($captcha); $i++) { $font = $this->fonts[array_rand($this->fonts)]; imagettftext($im, $this->font_size, mt_rand(-2, 2), $x, $this->base[1] + mt_rand(-2, 2), $fg, $font, $captcha[$i]); $x += $this->font_char_width; } switch ($this->img_type) { case 'jpeg': $filename = $prefix . '.jpeg'; imagejpeg($im, $this->tmp_dir . $filename); break; case 'gif': $filename = $prefix . '.gif'; imagegif($im, $this->tmp_dir . $filename); break; case 'png': default: $filename = $prefix . '.png'; imagepng($im, $this->tmp_dir . $filename); } imagedestroy($im); } if ($fh = fopen($this->tmp_dir . $prefix . '.php', 'w')) { fwrite($fh, '<?php $captcha = "' . $captcha . '"; ?>'); fclose($fh); } return $filename; } function check($prefix, $response) { if (is_readable($this->tmp_dir . $prefix . '.php')) { include($this->tmp_dir . $prefix . '.php'); if (0 == strcasecmp($response, $captcha)) return true; } return false; } function remove($prefix) { $suffixes = array('.jpeg', '.gif', '.png', '.php'); foreach ($suffixes as $suffix) { $file = $this->tmp_dir . $prefix . $suffix; if (is_file($file)) unlink($file); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956530 Share on other sites More sharing options...
MadTechie Posted November 13, 2009 Share Posted November 13, 2009 okay, the folder that captcha.php is in, you should have another folder called 'gentium' inside that you should have the following fonts GenAI102.TTF GenAR102.TTF GenI102.TTF GenR102.TTF' on unix this is case sensitive So for example this path should be valid /home/xxx/public_html/wp-content/plugins/mm-forms/captcha/gentium/GenAI102.TTF Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956536 Share on other sites More sharing options...
jrp91384 Posted November 13, 2009 Author Share Posted November 13, 2009 okay, the folder that captcha.php is in, you should have another folder called 'gentium' inside that you should have the following fonts GenAI102.TTF GenAR102.TTF GenI102.TTF GenR102.TTF' on unix this is case sensitive So for example this path should be valid /home/xxx/public_html/wp-content/plugins/mm-forms/captcha/gentium/GenAI102.TTF That is exactly how it is. I have the following. /home/xxx/public_html/wp-content/plugins/mm-forms/captcha/gentium/GenAI102.TTF /home/xxx/public_html/wp-content/plugins/mm-forms/captcha/cpatcha.php Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956543 Share on other sites More sharing options...
MadTechie Posted November 13, 2009 Share Posted November 13, 2009 do you have the other 3 files ? GenAR102.TTF GenI102.TTF GenR102.TTF Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956550 Share on other sites More sharing options...
jrp91384 Posted November 13, 2009 Author Share Posted November 13, 2009 do you have the other 3 files ? GenAR102.TTF GenI102.TTF GenR102.TTF Yes in the same location. Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956556 Share on other sites More sharing options...
MadTechie Posted November 13, 2009 Share Posted November 13, 2009 Okay well that should be fine, of course assuming the case is the same, it maybe worth connecting via FTP and checking the permission and file size, while your their upload another font, ie arial.ttf into the captcha folder, then (if no changes were made to the gentium fonts) update captcha.php from $this->fonts = array( dirname(__FILE__) . '/gentium/GenAI102.TTF', dirname(__FILE__) . '/gentium/GenAR102.TTF', dirname(__FILE__) . '/gentium/GenI102.TTF', dirname(__FILE__) . '/gentium/GenR102.TTF'); to $this->fonts = array( dirname(__FILE__) . '/arial.ttf'); assuming that works, you can repeat the test with each font, $this->fonts = array( dirname(__FILE__) . '/gentium/GenAI102.TTF'); then $this->fonts = array( dirname(__FILE__) . '/gentium/GenAR102.TTF'); etc etc Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956562 Share on other sites More sharing options...
jrp91384 Posted November 13, 2009 Author Share Posted November 13, 2009 Okay well that should be fine, of course assuming the case is the same, it maybe worth connecting via FTP and checking the permission and file size, while your their upload another font, ie arial.ttf into the captcha folder, then (if no changes were made to the gentium fonts) update captcha.php from $this->fonts = array( dirname(__FILE__) . '/gentium/GenAI102.TTF', dirname(__FILE__) . '/gentium/GenAR102.TTF', dirname(__FILE__) . '/gentium/GenI102.TTF', dirname(__FILE__) . '/gentium/GenR102.TTF'); to $this->fonts = array( dirname(__FILE__) . '/arial.ttf'); assuming that works, you can repeat the test with each font, $this->fonts = array( dirname(__FILE__) . '/gentium/GenAI102.TTF'); then $this->fonts = array( dirname(__FILE__) . '/gentium/GenAR102.TTF'); etc etc I will give that a try. Thank you so much for the help! Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956563 Share on other sites More sharing options...
jrp91384 Posted November 13, 2009 Author Share Posted November 13, 2009 Well not sure why but it works outside the folder. Thank you sooo much for all the help MadTechie!! I really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/181324-solved-invalid-font-filename/#findComment-956600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.