PHP-imagettftext不工作且已安装GD

PHP-imagettftext不工作且已安装GD,php,image,gd,imagettftext,Php,Image,Gd,Imagettftext,一直以来我都在寻找这个问题的答案。。 我找到的所有解决方案都围绕着字体名称,但我很确定这不是我的问题 似乎安装了GD array(11) { ["GD Version"]=> string(27) "bundled (**2.0.34 compatible**)" ["FreeType Support"]=> bool(false) ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=>

一直以来我都在寻找这个问题的答案。。 我找到的所有解决方案都围绕着字体名称,但我很确定这不是我的问题

似乎安装了GD

array(11) {
  ["GD Version"]=>
  string(27) "bundled (**2.0.34 compatible**)"
  ["FreeType Support"]=>
  bool(false)
  ["T1Lib Support"]=>
  bool(false)
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(true)
  ["XBM Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)
}
上面你可以看到我的GD支持。 我的PHP版本是5.3,在Linux上运行

我从不同的网站上尝试了几个不同的代码示例,但都不起作用。 ImageString确实适用于我,但我需要使用imagettftext

这是我现在尝试的最后一个代码-

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 100) or die("Can't create image!");

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, 'arial.ttf', $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, 'arial.ttf', $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

注意,您没有安装免费类型:

["FreeType Support"]=>
  bool(false)
此函数需要GD库和»FreeType库。

header('Content-Type:image/png');
在使用此函数之前,您需要安装免费类型库

尝试安装以下软件包:sfreetype,freetype-devel

如果编译PHP,可以确保在编译期间添加了启用的freetype:

--with-freetype-dir=/usr/include/freetype2/ --with-freetype

或者,如果您使用诸如YUM或APT-GET之类的工具,那么安装这些库应该非常简单,并且可以通过google快速搜索GET you Start。

也有同样的问题,安装FreeType后,解决方案是

 $font = "./Arial.ttf"; // <--- put ./ in front of filename
$font=“/Arial.ttf”// Andrew是对的,states FreeType需要使用
imagettftext
imagettfbox
等。大多数人GD-devel软件包将自动安装FreeType:

软呢帽/红帽:

yum install gd gd-devel php-gd
Debian/Ubuntu:

apt-get install php5-gd libgd2-xpm libgd2-xpm-dev
此错误可能在您的日志中:

PHP Fatal error:  Call to undefined function imageTTFText()

我也有问题

$font='arial.tff'; 
我认为您应该提供$font类的绝对路径

$font="c:/windows/fonts/arial.ttf";
我假定您是windows用户。 和删除

header('Content-Type:image/png');

要获得真正的错误,我使用此解决方案解决了此问题:

$fontfile= __DIR__.'/Fontname.ttf';

如果你设置标题。。。在imagepng之前,您得到了什么errormsg?php是否给您任何错误/通知?
imagettftext
函数返回什么?它应该返回点数组或错误时返回false。尝试
$text\u result=imagettftext(…);if($text_result===false){echo(“ERROR”);}else打印($text_result)。另一件事是,当你正在填充新创建的图像时,你在高度上只留下一个像素,在宽度上只填充了29个像素,这是故意的吗?你是如何打印这个数组的???请考虑接受一个答案(点击左边的刻度标记),如果它实际上回答了你对Fielype支持的问题的要求在PHP手册中被记录下来的话,看到了吧,为我工作!英雄联盟你能详细解释一下为什么会这样吗?对不起,我不知道为什么会这样!成功了但真的很奇怪,我也想知道为什么会发生这种情况?我甚至不得不添加realpath('./Arial.ttf')defined('ROOT_PATH')| | define('ROOT_PATH',realpath(dirname(FILE)。'')$font_path=根路径。'/fonts/arial italic.ttf';添加本地路径可能不是一个完美的解决方案,可能使用getcwd()+文件名。@Damiani您完全正确,但此路径适用于操作系统中安装的字体,我将更新答案。谢谢你的宝贵建议