Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35

前端 未结 10 2003
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 21:02


        
相关标签:
10条回答
  • 2020-12-03 21:27

    I had same problem. My font name was

    Titr.TTF

    and i changed it to

    Titr.ttf

    and its worked perfectly.

    0 讨论(0)
  • 2020-12-03 21:31

    To add on to user2724960's answer; Changing the FontName to __DIR__ . '/graph/fonts/someFont.ttf' did it for me.

    Full line:

    $myPicture->setFontProperties(array("FontName"=>__DIR__ .  '/graph/fonts/someFont.ttf',"FontSize"=>14));
    

    Don't forgot to replace "someFont" with the name of your font file (default: "Forgotte")

    0 讨论(0)
  • 2020-12-03 21:31

    I came across the same issue while working on localhost (XAMPP).

    My solution was:

    // Set Correct Path to Font File
    $fontPath='C:\xampp\htdocs\Adeplay\fonts\Tesox\tesox.ttf'; 
    
    0 讨论(0)
  • 2020-12-03 21:32

    it worked for me : use absolute path

    $font = 'C:\wamp\www\Persian-txt2img\Vazir-Code.ttf';
    $font = mb_convert_encoding($font, 'big5', 'utf-8');
    
    // Add the text
    imagettftext($image, 24, 0, 64, 48, $text_color, $font, $text);
    
    0 讨论(0)
  • 2020-12-03 21:33

    I am also on XAMPP, apparently XAMPP does only support full directory path to the font. This code works both on Windows (XAMPP) and on our providers Linux server:

    $dir= dirname(realpath(__FILE__));
    $sep=DIRECTORY_SEPARATOR;   
    $font =$dir.$sep.'arial.ttf';
    imagettftext($thumb, $size, 0, $y_pos, $size, $textcolor, $font, $txt);
    

    (assuming that your font file is in the same directory as your php file)

    0 讨论(0)
  • 2020-12-03 21:43

    From the docs

    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.

    This seems to imply that the fontfile should be an absolute path, and if it isn't, the function will append another .ttf onto the end of it.

    Specify the full path to the font file.

    $font = "/home/a2424901/public_html/Arial.ttf";
    

    Or omit the .ttf and use the GDFONTPATH. The documentation recommends the following:

    In many cases where a font resides in the same directory as the script using it the following trick will alleviate any include problems.

    putenv('GDFONTPATH=' . realpath('.'));
    $font = "Arial";
    
    0 讨论(0)
提交回复
热议问题