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

tec*_*l87 3 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
Run Code Online (Sandbox Code Playgroud)

但没有得到任何东西.

Dev*_*er0 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.
Run Code Online (Sandbox Code Playgroud)

然后你可以安全地使用"font.ttf" imagettftext

 imagettftext($im, 20, 0, 11, 21, $grey, "font.ttf", $text);
Run Code Online (Sandbox Code Playgroud)