PHP imagettftext 无效的字体文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11008066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:33:56  来源:igfitidea点击:

PHP imagettftext invalid font filename

phpgdtrue-type-fonts

提问by legobear154

I am trying to create an image with text by using imagettftext. It is telling me Warning: imagettftext(): Invalid font filename in C:\xampp\htdocs\recentpost.php on line 32. Here is the code on line 32 I am using to add the text

我正在尝试使用 imagettftext 创建带有文本的图像。它告诉我警告:imagettftext(): Invalid font filename in C:\xampp\htdocs\recentpost.php 第 32 行。这是我用来添加文本的第 32 行代码

imagettftext($img, 12, 0, 20, 1, $black, "../fonts/arial.ttf", "News!");

I copied the font right out of the C:/Windows/Fonts folder so it is a valid font.

我直接从 C:/Windows/Fonts 文件夹中复制了字体,因此它是有效字体。

回答by Sudhir Bastakoti

Try something like:

尝试类似:

$font = dirname(__FILE__) . '/arial.ttf';
//OR
$font = dirname(__FILE__) . '/fonts/arial.ttf';    
imagettftext($img, 12, 0, 20, 1, $black, $font, "News!");

Hope it helps

希望能帮助到你

回答by Fab V.

If you are on Windows, you should use "..\fonts\arial.ttf"as path I think

如果你在 Windows 上,你应该使用"..\fonts\arial.ttf"我认为的路径

回答by Sebr

Have you tried using

你有没有试过使用

imagettftext($img, 12, 0, 20, 1, $black, "../fonts/arial.TTF", "News!");

instead? (.TTF instead of .ttf)

反而?(.TTF 而不是 .ttf)

and @Fab, you can use both \ and / on windows.

和@Fab,您可以在Windows 上同时使用\ 和/。

回答by legobear154

Oh wow, stupid me... Its too late for me to be up working on php :p I was trying to get to get to a non existing folder. The real code should be

哦,哇,愚蠢的我......对我来说开始处理 php 为时已晚:p 我正试图进入一个不存在的文件夹。真正的代码应该是

imagettftext($img, 12, 0, 20, 1, $black, "fonts/arial.ttf", "News!");

Thank you everyone for trying to fix my silly mistake :p

谢谢大家试图纠正我的愚蠢错误:p

回答by gardist

Try to use double slash:

尝试使用双斜线:

imagettftext($img, 12, 0, 20, 1, $black, "..\fonts\arial.ttf", "News!");