警告 - 无效的字体文件名

时间:2018-01-27 12:59:15

标签: php

问题

我遇到运行时错误,上面写着 - 字体文件名无效。我在Window 8.1中使用XAMPP

好像我需要映射C:\ XAMPP中存在的任何字体文件夹路径,或者请建议。

$jpg_image = imagecreatefromjpeg('sunset.jpg');
$white = imagecolorallocate($jpg_image, 255, 255, 255);
$font_path = 'font.TTF';
$text = "This is a sunset!";
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

2 个答案:

答案 0 :(得分:2)

您必须使用putenv定义路径:

putenv('GDFONTPATH=' . realpath('.'));
$font_path = 'font'; // no .ttf

查看http://php.net/imagettftext

答案 1 :(得分:0)

当您为imagettftext()设置字体时,需要使用/启动字体名称,否则.TTF将自动添加。{/ p>

  

根据PHP使用的GD库版本,当fontfile不以前导/开头时,然后.ttf将附加到文件名,库将尝试沿库定义的字体路径搜索该文件名

资源:php.net/imagettftext

所以你的字体声明应如下所示:

// this is if your font is in the default GD directory
$font_path = 'font';

// default directory is set by
putenv('GDFONTPATH=' . realpath('.'));

或者您可以指定字体的完整路径:

// font is in some other directory
$font_path = '/path/to/font.ttf';
相关问题