我在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 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,如您所见:

有谁能告诉我正确的方向吗?
发布于 2014-11-04 18:43:47
将变量$font赋给字体文件的绝对路径。
发布于 2014-11-04 18:54:33
// Replace path by your own font path
$font = 'arial.ttf';您的代码正在查找不存在的"arial.ttf“。请将字体文件(arial.ttf)复制到与代码相同的目录中。
发布于 2021-03-18 15:35:37
尝试替换您的字体路径
$font = 'arial.ttf';在……上面
$font = __DIR__ .'\Arial.ttf';或者使用绝对路径(这不正确,但工作),如果你使用windows系统
$font = 'c:\WINDOWS\Fonts\Arial.ttf';https://stackoverflow.com/questions/26732382
复制相似问题