繁体   English   中英

PHP GD 库 - 文本/字体不显示

[英]PHP GD Library - Text / Font NOT Showing

I am able to render the PHP GD image just fine on my localhost, but when I upload it to my Linux Ubuntu Debian LAMP server, the font or text is missing and only the background color shows. 所以正在生成图像,但它只是缺少属于图像的文本。

我目前安装了 PHP 7.2 和 GD 7.2 库。 它还在我的 php.ini 文件中显示我已启用它,甚至删除了分号以确保它也已启用。

这是我正在使用的代码:

<?php

//create the php image
header('Content-type: image/jpeg');

$img = imagecreate(200, 60);

$background = imagecolorallocate($img, 1,49,31);
$textColor = imagecolorallocate($img, 255, 255, 255);
$font = "roboto.ttf";

imagettftext($img, 28, 10, 40, 50, $textColor, $font, "MY TEXT GOES HERE!");
imagejpeg($img);
imagedestroy($img);

?>

有什么线索会阻止文本出现吗?

经过几个小时的研究,我解决了这个问题。

当您在 VPS 上有字体文件并使用 Linux 时,您需要改用以下文件路径:

$font = "./myfont.ttf"

如果你不放点和正斜杠,文件将不会在服务器上找到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM