Jump to content

[SOLVED] Invalid font filename


jrp91384

Recommended Posts

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

Link to comment
Share on other sites

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);
	}
}
}

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.