Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imagettftext function using font from remote server

Tags:

php

gd

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.

like image 568
techrahul87 Avatar asked Apr 20 '26 23:04

techrahul87


1 Answers

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);
like image 182
DevZer0 Avatar answered Apr 23 '26 13:04

DevZer0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!