imagettftext没有';不要输出任何内容


imagettftext doesn't output anything

我在本地机器(Macbook Pro w/Snow Leopard)上使用php.net中的基本示例来使用GD库显示一行文本,但没有显示任何内容。我打开了显示错误,并仔细检查了GD库和FreeType库是否正在使用,但我仍然看到空白的白色页面。这是我正在测试的代码,直接取自http://php.net/manual/en/function.imagettftext.php

我怀疑是"arial.ttf"部分造成了问题。有什么办法让我测试一下吗?我想默认安装肯定会有这个功能。

// 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:的PHP信息

GD Support  enabled
GD Version  bundled (2.0.34 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.4.4
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support    enabled
libJPEG Version 8
PNG Support enabled
libPNG Version  1.5.2
WBMP Support    enabled
XBM Support enabled

默认情况下,PHP不提供字体文件"arial.ttf"。

您的脚本需要访问字体文件才能使用它。