Jump to content

Quick Question: Using TTF font with GD not working


cs.punk

Recommended Posts

Ok with this simple code:

<?php
     header ("Content-type: image/png");
   
     $im = ImageCreate (300, 40);
     $grey = ImageColorAllocate ($im, 230, 230, 230);
     $black = ImageColorAllocate ($im, 0, 0, 0);
   
     ImageTTFText($im, 20, 0, 10, 25, $black, "arial.ttf", "TrueType Fonts!");
     ImagePng ($im);
     ImageDestroy ($im);
?>

 

It just gives me a non-exsistent image.

 

I am using xampp. Should I load the font first? In which directory?

Try putting the ttf file in the same folder as the script. You may need to use a better reference to the font, like ./arial.ttf

 

 

HTH

Teamatomic

 

Thanks! Exactly what I needed!

 

If the font is not within GD's predefined library path, it will attempt to search for that filename along a library-defined font path.

 

Note the following example:

// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';

 

Otherwise you can do as intended and point the font to the relative path.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.