Problem using font with imagettftext

拜拜、爱过 提交于 2019-12-24 04:44:09

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5566236/problem-using-font-with-imagettftext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!