문제

its working perfect, until i try to use a font for text.

This is my code.. The 3er line commented now is the one that works fine... but in this example im trying to replace this line with imagettftext.. not lucky.

Whats my error?

$newImage = imagecreatefromjpeg( "orsil_secure.jpg" ); 

$txtColor = imagecolorallocate($newImage, 0, 0, 0); 

//imagestring($newImage, 5, 10, 27, $ranStr,  $txtColor); 

imagettftext($newImage, 5, 10, 27, $txtColor, $font_path, $ranStr);

header( "Content-type: image/jpeg" ); 

imagejpeg($newImage); 

Oh yes in the previous lines is the route to the font here:

// random number

$ranStr = md5(microtime()); 

$ranStr = substr($ranStr, 0, 6); 

// Set Path to Font File
  $font_path = 'captcha.TTF';
도움이 되었습니까?

해결책

It looks like you have the wrong parameters in your call to imagettftext.

Presumably, the 5 corresponds to the font used in imagestring, but has no place in imagettftext. You also need to specify the size and angle.

For example:

imagettftext($newImage, 12, 45, 10, 27, $txtColor, $font_path, $ranStr);
                        ^^  ^^
                        ||  ||
                        ||   ------ angle
                        ----------- size

In this example:

size=12px or 12pt, depending on whether you're using GD1 or GD2

angle = 45°

Obviously, you'll want to use your own values here.

If it still isn't working, then it's likely that the path to your font file is wrong. Check to see if it's in the same folder as the PHP script.

다른 팁

I think you are missing a parameter in your imagettftext. If you look at http://php.net/manual/en/function.imagettftext.php it has size, angle, x and y.
You are missing one of the 4 (im guessing the angle).

So it needs to be something like:

imagettftext($newImage, 5, 0, 10, 27, $txtColor, $font_path, $ranStr);

Where 0 is for angle.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top