


求助:Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename
//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
$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 $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
回复讨论(解决方案)
没有那个字体 换一个字体或把字体文件拷到相对应的目录
在C盘路径下 有arial字体文件啊。
我把putenv('GDFONTFATH=C:\windows\fonts');
改成putenv('GDFONTFATH=C:\Windows\Fonts');
报错为:Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in E:\AppServ\www\make_button.php on line 38
但是在文件夹中的确有Arial字体文件
请大侠帮助!~~~
不好意思
报错一直为 Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in E:\AppServ\www\make_button.php on line 38
是字体变量的问题。把
putenv('GDFONTFATH=C:\windows\fonts');
$fontname='Arial';
直接改成
$fontname = 'c:/windows/fonts/arial.ttf'就可以了,大小写不敏感。
我也遇到了这种情况,也按照#4楼的做了,还是出现那种情况,找不到文件名
字体路径的反斜杠是怎么写的,是\还是/,我试了好几种,都不行,并且字体在系统中存在
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
我的问题出现在调用的类里面,,你们怎么看?
4楼的方法解决了,谢谢.
4楼正解,3KU!
4楼方法管用!

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Laravel simplifie la gestion des données de session temporaires à l'aide de ses méthodes de flash intuitives. Ceci est parfait pour afficher de brefs messages, alertes ou notifications dans votre application. Les données ne persistent que pour la demande ultérieure par défaut: $ demande-

L'extension PHP Client URL (CURL) est un outil puissant pour les développeurs, permettant une interaction transparente avec des serveurs distants et des API REST. En tirant parti de Libcurl, une bibliothèque de transfert de fichiers multi-protocol très respectée, PHP Curl facilite Efficient Execu

Laravel fournit une syntaxe de simulation de réponse HTTP concise, simplifiant les tests d'interaction HTTP. Cette approche réduit considérablement la redondance du code tout en rendant votre simulation de test plus intuitive. L'implémentation de base fournit une variété de raccourcis de type de réponse: Utiliser illuminate \ support \ faades \ http; Http :: faux ([[ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Voulez-vous fournir des solutions instantanées en temps réel aux problèmes les plus pressants de vos clients? Le chat en direct vous permet d'avoir des conversations en temps réel avec les clients et de résoudre leurs problèmes instantanément. Il vous permet de fournir un service plus rapide à votre personnalité

Alipay Php ...

L'article traite de la liaison statique tardive (LSB) dans PHP, introduite dans PHP 5.3, permettant une résolution d'exécution de la méthode statique nécessite un héritage plus flexible. Problème main: LSB vs polymorphisme traditionnel; Applications pratiques de LSB et perfo potentiel

L'article examine l'ajout de fonctionnalités personnalisées aux cadres, en se concentrant sur la compréhension de l'architecture, l'identification des points d'extension et les meilleures pratiques pour l'intégration et le débogage.

L'article traite des fonctionnalités de sécurité essentielles dans les cadres pour se protéger contre les vulnérabilités, notamment la validation des entrées, l'authentification et les mises à jour régulières.
