我正在尝试使用imagettftext()通过PHP向图像添加文本。到目前为止,我已经浏览了大约6个不同的教程,试图让它起作用,而且我没有成功。我目前正在从PHP文档页面尝试此代码。imagettftext不会工作;文字不显示
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// 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, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
然而,没有出现。我安装了GD库,并启用了freetype。我有arial.ttf在与php文件相同的目录中,我无法弄清楚为什么它不会工作。我得到的只是一张空白图片。编辑:这是错误信息“[19-Jan-2014 16:31:07] PHP警告:imagettftext():找不到/打开/var/www/php/bb/test.php中的字体在线21“
2014-01-19
C A Mc
+0
请登录错误的文件,并张贴在这里,'的ini_set( “log_errors”,1); ini_set(“error_log”,“php-error.log”);'不要忘记在你的脚本的相同目录中创建文件'php-error.log',并为其写入权限。 –
+0
我得到这个错误“[19-Jan-2014 16:31:07] PHP警告:imagettftext():找不到/ var/21 -Jan-2014 16:31:08]“。我确定在同一个目录中有arial.ttf,所以我不知道为什么发生这种情况 –
+0
我测试了你的确切代码和它的工作 –