It's being long hours that I'm still looking for answer to this problem.. All the solutions I find are around catching the font name but I am pretty sure this isn't my problem.
很长时间以来,我一直在寻找这个问题的答案。我找到的所有解决方案都是关于查找字体名称,但我很确定这不是我的问题。
It looks like GD is installed
看起来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)
}
Above you can see my GD support. My PHP version is 5.3 and I'm running on Linux.
在上面你可以看到我的GD支持。我的PHP版本是5.3,我在Linux上运行。
I have tried few different code examples from different websites and none works. ImageString does work for me but I need to get imagettftext to work..
我从不同的网站尝试过几个不同的代码示例,但没有一个是有效的。ImageString确实适合我,但是我需要让imagettftext生效。
This is the last code I have tried 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);
?>
Result: http://www.7679679.com/app/test-ansi.php
结果:http://www.7679679.com/app/test-ansi.php
4 个解决方案
#1
14
Had the same problem, with FreeType installed, solution was
有同样的问题,用FreeType安装,解决是吗
$font = "./Arial.ttf"; // <--- put ./ in front of filename
#2
6
Notice you don't have Free Type installed:
注意,您没有安装免费类型:
["FreeType Support"]=>
bool(false)
This function requires both the GD library and the » FreeType library.
这个函数需要GD库和»FreeType库。
You will need to install Free Type library before you can use this function.
在使用这个函数之前,您需要安装免费类型库。
try installing these package:s freetype, freetype-devel
试着安装这些软件包:s freetype, freetype-devel
If you compiled PHP you can make sure you added enabled freetype during compile time:
如果您编译了PHP,您可以确保您在编译期间添加了启用的freetype:
--with-freetype-dir=/usr/include/freetype2/ --with-freetype
Or if you using something such as YUM or APT-GET it should be really simple to install those libraries, and a quick search ob google with get you started.
或者,如果您使用YUM或APT-GET之类的东西,那么安装这些库应该非常简单,然后启动一个快速搜索ob谷歌。
#3
2
Well i also got problem around
我也遇到了一些问题
$font='arial.tff';
I think you should provide absolute path to the $font like
我认为您应该提供类似$字体的绝对路径
$font="c:/windows/fonts/arial.ttf";
i assume you are a windows user. and remove
我猜你是windows用户。和删除
header('Content-Type:image/png');
to get the real error
得到真正的误差
#4
0
Andrew is right, the php manual for imagettftext states FreeType is required to use imagettftext
, imagettfbox
, and others. Most people the GD devel package will install FreeType automatically:
Andrew是正确的,imagettftext状态的php手册需要使用imagettftext、imagettfbox和其他。大多数人GD devel包会自动安装FreeType:
Fedora/Redhat:
Fedora / Redhat:
yum install gd gd-devel php-gd
Debian/Ubuntu:
Debian / Ubuntu:
apt-get install php5-gd libgd2-xpm libgd2-xpm-dev
This error was probably in your logs:
这个错误可能出现在你的日志中:
PHP Fatal error: Call to undefined function imageTTFText()
#1
14
Had the same problem, with FreeType installed, solution was
有同样的问题,用FreeType安装,解决是吗
$font = "./Arial.ttf"; // <--- put ./ in front of filename
#2
6
Notice you don't have Free Type installed:
注意,您没有安装免费类型:
["FreeType Support"]=>
bool(false)
This function requires both the GD library and the » FreeType library.
这个函数需要GD库和»FreeType库。
You will need to install Free Type library before you can use this function.
在使用这个函数之前,您需要安装免费类型库。
try installing these package:s freetype, freetype-devel
试着安装这些软件包:s freetype, freetype-devel
If you compiled PHP you can make sure you added enabled freetype during compile time:
如果您编译了PHP,您可以确保您在编译期间添加了启用的freetype:
--with-freetype-dir=/usr/include/freetype2/ --with-freetype
Or if you using something such as YUM or APT-GET it should be really simple to install those libraries, and a quick search ob google with get you started.
或者,如果您使用YUM或APT-GET之类的东西,那么安装这些库应该非常简单,然后启动一个快速搜索ob谷歌。
#3
2
Well i also got problem around
我也遇到了一些问题
$font='arial.tff';
I think you should provide absolute path to the $font like
我认为您应该提供类似$字体的绝对路径
$font="c:/windows/fonts/arial.ttf";
i assume you are a windows user. and remove
我猜你是windows用户。和删除
header('Content-Type:image/png');
to get the real error
得到真正的误差
#4
0
Andrew is right, the php manual for imagettftext states FreeType is required to use imagettftext
, imagettfbox
, and others. Most people the GD devel package will install FreeType automatically:
Andrew是正确的,imagettftext状态的php手册需要使用imagettftext、imagettfbox和其他。大多数人GD devel包会自动安装FreeType:
Fedora/Redhat:
Fedora / Redhat:
yum install gd gd-devel php-gd
Debian/Ubuntu:
Debian / Ubuntu:
apt-get install php5-gd libgd2-xpm libgd2-xpm-dev
This error was probably in your logs:
这个错误可能出现在你的日志中:
PHP Fatal error: Call to undefined function imageTTFText()