PHP - imagettftext无法正常工作并安装了GD [英] PHP - imagettftext not working and GD installed
问题描述
我需要很长时间才能找到这个问题的答案..
我找到的所有解决方案都是捕捉字体名称,但我很确定这不是我的问题。
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.
看起来已安装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上运行。
Above you can see my GD support. My PHP version is 5.3 and I'm running on Linux.
我尝试过来自不同网站的几个不同的代码示例,但都没有。
ImageString对我有用,但我需要 imagettftext 才能工作..
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..
这是我现在尝试的最后一个代码 -
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);
?>
结果: http://www.7679679.com/app/test-ansi.php
推荐答案
出现同样的问题,安装了FreeType,解决方案是
Had the same problem, with FreeType installed, solution was
$font = "./Arial.ttf"; // <--- put ./ in front of filename
这篇关于PHP - imagettftext无法正常工作并安装了GD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!