Problem using font with imagettftext

11,474

If you are using font which is in the same directory with script (no leading / at beggining) , type just arial without .ttf. If it is in another directory you must include .ttf. BTW: It would be nice if you could add code that you are using.

So here is example code:

# Correct
$font = 'arial'; 

# Wrong
$font = 'arial.ttf';


# Correct
$font = '/fonts/arial.ttf';

# Wrong
$font = '/fonts/arial';

PHP.NET says:

Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.

Share:
11,474

Related videos on Youtube

krifur
Author by

krifur

Updated on May 27, 2022

Comments

  • krifur
    krifur almost 2 years

    this is the error message i get when I change the environment of an effective website:

    Warning: imagettftext() [function.imagettftext]: Could not find/open font 
    

    First I was thinking it cames from a lack of rights on the files, but it doesn't, I check the path and set all the files in 777... Then I check GD, and it looks like it is installed :

    GD Support  enabled
    GD Version  bundled (2.0.34 compatible)
    FreeType Support    enabled
    FreeType Linkage    with freetype
    FreeType Version    2.3.5
    GIF Read Support    enabled
    GIF Create Support  enabled
    JPG Support     enabled
    PNG Support     enabled
    WBMP Support    enabled
    XBM Support     enabled 
    

    I'm trying to use an arial.ttf, so not much exotic I guess... Any idea where to start looking at ?

    Thx

  • krifur
    krifur about 13 years
    this is how it looks: var_dump($this->font); //string '/Shared\ Websites/largos/largos_site/trunk/commun/font/arialbd.ttf' imagettftext($this->im, $font_size,0, $x, $y, $this->textcolor, $this->font, $chaine);
  • krifur
    krifur about 13 years
    sorry for the appearance I do not know how to display properly a "comment"