imagettftext function using font from remote server

左心房为你撑大大i 提交于 2019-12-06 08:47:12

问题


I am creating an image form font size, font family, font color in php. Everything was working fine until I got a new requirement. I was using ttf files and passing the path of particular ttf file in imagettftext function as a parameter. Now I am using google fonts and I am not getting an idea how to get the font in my function. I tried using couple of things such as passing

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

But not getting any thing.


回答1:


first download the ttf file

$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.

then you can safely use "font.ttf" with imagettftext

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


来源:https://stackoverflow.com/questions/17313061/imagettftext-function-using-font-from-remote-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!