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

php中文网
发布: 2016-06-13 10:32:40
原创
1073人浏览过

求助: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


------解决方案--------------------
没有那个字体 换一个字体或把字体文件拷到相对应的目录
------解决方案--------------------
是字体变量的问题。把 
putenv('GDFONTFATH=C:\windows\fonts');
$fontname='Arial';

直接改成
$fontname = 'c:/windows/fonts/arial.ttf'就可以了,大小写不敏感。

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号