Help: Warning: imagettfbbox () [function. imagettfbbox]: Invalidfontfilename & lt ;? Php // checkwehavetheappropriatevariabledata // v help: Warning: imagettfbbox () [function. imagettfbbox]: Invalid font filename
// Check we have the appropriate variable data
// Variables are button-text and 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;
Warning: imagettfbbox () [function. imagettfbbox]: Invalid font filename in E: \ AppServ \ www \ make_button.php on line 38
------ Solution --------------------
There is no such font to change the font or copy the font file to the corresponding directory.
------ Solution --------------------
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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.