【问题标题】:imagettftext function using font from remote server使用来自远程服务器的字体的 imagettftext 函数
【发布时间】:2013-06-26 14:41:49
【问题描述】:

我正在 php 中创建图像形式的字体大小、字体系列、字体颜色。一切都很好,直到我有一个新的要求。 我正在使用 ttf 文件并将特定 ttf 文件的路径作为参数传递给 imagettftext 函数。 现在我正在使用谷歌字体,但我不知道如何在我的函数中获取字体。 我尝试使用一些东西,例如传递

1.http://fonts.googleapis.com/css?family=Tangerine<br/>
2.http://themes.googleusercontent.com/static/fonts/abel/v3/RpUKfqNxoyNe_ka23bzQ2A.ttf

但没有得到任何东西。

【问题讨论】:

  • 你需要在本地有字体文件。您发布的那些网址是在网页中使用的
  • @DevZer0 是的,我在本地使用,一切正常,但现在我必须使用谷歌字体,这就是我遇到问题的原因。我们有任何替代功能吗?
  • 在下面查看我的答案

标签: php gd


【解决方案1】:

先下载ttf文件

$font = file_get_contents("http://themes.googleusercontent.com/static/fonts/abel/v3/RpUKfqNxoyNe_ka23bzQ2A.ttf");
file_put_contents("font.ttf", $font); //be sure to save the font in the path you have provided as font path.

那么您就可以安全地使用“font.ttf”和imagettftext

 imagettftext($im, 20, 0, 11, 21, $grey, "font.ttf", $text);

【讨论】:

    猜你喜欢
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2015-08-12
    相关资源
    最近更新 更多