3

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.

techrahul87
  • 107
  • 2
  • 11
  • you need to have the font file locally. those urls you posted are for using in a web page – DevZer0 Jun 26 '13 at 06:39
  • @DevZer0 Yes I was using locally and everything was working fine, but now I have to use google fonts that is why I am getting problem. Do we have any alternate for function. – techrahul87 Jun 26 '13 at 06:42

1 Answers1

8

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);
DevZer0
  • 13,433
  • 7
  • 27
  • 51