-->

PHP - imagettftext不工作,并安装GD(PHP - imagettftext n

2019-08-17 02:28发布

它是很长时间,我还在寻找答案,这个问题..所有的解决方案,我发现周围的醒目字体的名字,但我敢肯定这是不是我的问题。

它看起来像安装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工作..

这是最后的代码,我已经试过NOW-

<?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);
?>

结果: http://www.7679679.com/app/test-ansi.php

Answer 1:

有同样的问题,安装的FreeType,溶液呈

 $font = "./Arial.ttf"; // <--- put ./ in front of filename


Answer 2:

注意:您没有安装免费类型的更多信息:

["FreeType Support"]=>
  bool(false)

该功能同时需要GD库和»FreeType库。

您需要安装免费的类型库,然后才能使用此功能。

尝试安装这些软件包:■FreeType的是,FreeType-devel的

如果你编译PHP你可以在编译时一定要加入启用的FreeType:

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

如果您使用的东西,如YUM或或APT-GET应该安装这些库很简单,用你开始一个快速搜索谷歌OB。



Answer 3:

嗯,我也得到了周围的问题

$font='arial.tff'; 

我想你应该在$字体提供绝对路径一样

$font="c:/windows/fonts/arial.ttf";

我假设你是一个Windows用户。 并删除

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

获得真正的错误



Answer 4:

安德鲁是正确的, 对于imagettftext PHP手册规定的FreeType需要使用imagettftextimagettfbox ,等等。 大多数人的GD devel包会自动安装的FreeType:

于Fedora /红帽:

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()


Answer 5:

我解决了这个问题,这个解决方案:

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


文章来源: PHP - imagettftext not working and GD installed