Help: Warning: imagettfbbox () [function. imagettfbbox]: Invalidfontfilename // Check we have the appropriate variable data
// Variables are button-text and color
$ Button_text = $ _ REQUEST ['Button _ text'];
$ Color = $ _ REQUEST ['color'];
If (empty ($ button_text) | empty ($ color) | (! ($ Color = 'red'
| $ Color = 'blue' | $ color = 'green ')))
{
Echo 'could not create image-form not filled out correctly ';
Exit;
}
// Create an image of the right background and check size
Required im‑imagecreatefrompng(%color.'-button.png ');
If (! $ Im)
{
Echo 'could not create image ';
Exit;
}
$ Width_image = imagesx ($ im );
$ Height_image = imagesy ($ im );
// Our images need an 18 pixel margin in from the edage of the image
$ Width_image_wo_margins = $ width_image-(2*18 );
$ Height_image_wo_margins = $ height-(2*18 );
// Work our if the font size will fit and make itsmaller until it does
// Start our with the biggest size that will reasonably fit on our buttons
$ Font_size = 3;
// You need to tell GD2 where fonts reside
Putenv ('gdfontfath = C: \ windows \ fonts ');
$ Fontname = 'arial ';
Do
{
$ Font_size --;
// Find out the size of the text at that font size
$ Bbox = imagettfbbox ($ font_size, 0, $ fontname, $ button_text );
$ Right_text = $ bbox [2]; // right co-ordinate
$ Left_text = $ bbox [0];
$ Width_text = $ right_text-$ left_text; // how wide is it?
$ Height_text = abs ($ bbox [7]-$ bbox [1]); // how tall is it?
}
While ($ font_size> 8 & ($ height_text> $ height_image_wo_margins |
$ Width_text> $ width_image_wo_margins)
);
If ($ height_text> $ height_image_wo_margins |
$ Width_text> $ width_image_wo_margins)
{
// No readable font size will fit on button
Echo 'text given will not fit on button.
';
}
Else
{
// We have found a font size that will fit
// Now work out where to put it
$ Text_x = $ width_image/2.0-$ width_text/2/0;
$ Text_y = $ height_image/2.0-$ height_text/2.0;
If ($ left_text <0)
$ Text_x + = abs ($ left_text );
$ Above_line_text = abs ($ bbox [7]);
$ Text_y + = $ above_line_text;
$ Text_y-= 2;
$ White = imagecolorallocate ($ im, 255,255,255 );
Imagettftext ($ im, $ font_size, 0, $ text_x, $ text_y, $ white, $ fontname,
$ Button_text );
Header ('content-type: image/png ');
Imagepng ($ im );
}
Imagedestroy ($ im );
?>
Warning: imagettfbbox () [function. imagettfbbox]: Invalid font filename in E: \ AppServ \ www \ make_button.php on line 38
Reply to discussion (solution)
There is no such font to change the font or copy the font file to the corresponding directory.
There is an arial font file in the drive C path.
I set putenv ('gdfontfath = C: \ windows \ fonts ');
Change to putenv ('gdfontfath = C: \ Windows \ fonts ');
Error: Warning: imagettfbbox () [function. imagettfbbox]: cocould not find/open font in E: \ AppServ \ www \ make_button.php on line 38
But there are indeed Arial font files in the folder.
Please help !~~~
Sorry
The error is always "Warning: imagettfbbox () [function. imagettfbbox]: Invalid font filename in E: \ AppServ \ www \ make_button.php on line 38 ".
Is the problem of font variables. Set
Putenv ('gdfontfath = C: \ windows \ fonts ');
$ Fontname = 'arial ';
Directly change
$ Fontname = 'C:/windows/fonts/arial. ttf'. it is case insensitive.
I also encountered this kind of situation. I also followed the steps on the 4 th floor of #, but the file name still failed to be found.
How do I write the backslash of the font path? \ or/? I tried several methods, but none of them work, and the font exists in the system.
Warning: imagettfbbox () [function. imagettfbbox]: Invalid font filename in D: \ xampp \ htdocs \ test \ class \ pImage. class. php on line 211
Warning: imagettftext () [function. imagettftext]: Invalid font filename in D: \ xampp \ htdocs \ test \ class \ pDraw. class. php on line 1023
My problem occurs in the called class. what do you think?
Solution on the 4th floor. thank you.
Solution on the 4th floor, 3KU!
The method works on the 4th floor!