imagettftext函数使用远程服务器的字体

时间:2013-06-26 06:33:14

标签: php gd

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

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

但没有得到任何东西。

1 个答案:

答案 0 :(得分:9)

首先下载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);