目录
回复讨论(解决方案)
首页 后端开发 php教程 求助:Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename

求助:Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename

Jun 23, 2016 pm 02:25 PM

//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楼方法管用!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

在Laravel中使用Flash会话数据 在Laravel中使用Flash会话数据 Mar 12, 2025 pm 05:08 PM

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

php中的卷曲:如何在REST API中使用PHP卷曲扩展 php中的卷曲:如何在REST API中使用PHP卷曲扩展 Mar 14, 2025 am 11:42 AM

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

简化的HTTP响应在Laravel测试中模拟了 简化的HTTP响应在Laravel测试中模拟了 Mar 12, 2025 pm 05:09 PM

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

在Codecanyon上的12个最佳PHP聊天脚本 在Codecanyon上的12个最佳PHP聊天脚本 Mar 13, 2025 pm 12:08 PM

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

解释PHP中晚期静态结合的概念。 解释PHP中晚期静态结合的概念。 Mar 21, 2025 pm 01:33 PM

文章讨论了PHP 5.3中引入的PHP中的晚期静态结合(LSB),从而允许静态方法的运行时分辨率调用以获得更灵活的继承。 LSB的实用应用和潜在的触摸

框架安全功能:防止漏洞。 框架安全功能:防止漏洞。 Mar 28, 2025 pm 05:11 PM

文章讨论了框架中的基本安全功能,以防止漏洞,包括输入验证,身份验证和常规更新。

自定义/扩展框架:如何添加自定义功能。 自定义/扩展框架:如何添加自定义功能。 Mar 28, 2025 pm 05:12 PM

本文讨论了将自定义功能添加到框架上,专注于理解体系结构,识别扩展点以及集成和调试的最佳实践。

See all articles