我在本地机器上使用php.net的基本示例(Macbook Pro w / Snow Leopard)使用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
答案 0 :(得分:1)
默认情况下,PHP不提供字体文件“arial.ttf”。
您的脚本需要访问字体文件才能使用它。