无效的字体文件名无法在 PHP 中使用 .ttf 文件
Invalid font filename unable to use .ttf file in PHP
我正在尝试使用 imagettftext 向 PHP 中的图像添加文本。但是,它似乎不接受任何 .ttf 文件并不断给出错误:'Could not find/open font' 和 'Invalid font filename'。文件路径为localhost/fonts/arial.ttf
我尝试了相对路径、绝对路径,将 /
更改为 \
,尝试将 ../
放在路径之前,但似乎没有任何效果。
我已经检查了 GD 版本及其 2.1.0 和 FreeType 链接是 'with freetype' 无论如何。
<?php
$output = "pics/email.png";
$x = 720;
$y = 480;
$image = imagecreate($x, $y);
//colors to use (rgb)
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$font = 'fonts/arial.ttf';
$text1 = imagettftext($image, 40, 0, 20, 40, $black, $font, "Text Sample");
imagejpeg($image, $output);
var_dump(gd_info());
?>
如果有人能给出有效的答案,我将不胜感激。
已经解决了,感谢评论区的大佬
我只需要使用完整的文件路径 (C://.../fonts/arial.ttf)
我正在尝试使用 imagettftext 向 PHP 中的图像添加文本。但是,它似乎不接受任何 .ttf 文件并不断给出错误:'Could not find/open font' 和 'Invalid font filename'。文件路径为localhost/fonts/arial.ttf
我尝试了相对路径、绝对路径,将 /
更改为 \
,尝试将 ../
放在路径之前,但似乎没有任何效果。
我已经检查了 GD 版本及其 2.1.0 和 FreeType 链接是 'with freetype' 无论如何。
<?php
$output = "pics/email.png";
$x = 720;
$y = 480;
$image = imagecreate($x, $y);
//colors to use (rgb)
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$font = 'fonts/arial.ttf';
$text1 = imagettftext($image, 40, 0, 20, 40, $black, $font, "Text Sample");
imagejpeg($image, $output);
var_dump(gd_info());
?>
如果有人能给出有效的答案,我将不胜感激。
已经解决了,感谢评论区的大佬
我只需要使用完整的文件路径 (C://.../fonts/arial.ttf)