警告:imagettftext() [function.imagettftext]:在第 35 行的 /home/a2424901/public_html/index.php 中找不到/打开字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10366679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35
提问by Nishant Ghodke
<?php
session_start();
require_once 'facebook.php';
$app_id = "418907881455014";
$app_secret = "36389d2c4caaf6de86982cb87686a494";
$redirect_uri = 'http://gooogle12.comuf.com';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');
$coded = $_REQUEST['code'];
$access_token = $facebook->getAccessToken();
$name = "".$user_profile['name']."";
$fbid = "".$user_profile['id']."";
function RandomLine($filename) {
$lines = file($filename) ;
return $lines[array_rand($lines)] ;
}
$reason = RandomLine("reason.txt");
$canvas = imagecreatefromjpeg ("bg.jpg"); // background image file
$black = imagecolorallocate( $canvas, 0, 0, 0 ); // The second colour - to be used for the text
$font = "Arial.ttf"; // Path to the font you are going to use
$fontsize = 20; // font size
$birthday = "".$user_profile['birthday']."";
$death = "- ".date('d/m/Y', strtotime( '+'.rand(0, 10000).' days'))."";
imagettftext( $canvas, 22, -1, 110, 120, $black, $font, $name ); // name
imagettftext( $canvas, 22, -1, 110, 170, $black, $font, $birthday ); // birthday
imagettftext( $canvas, 22, -1, 255, 172, $black, $font, $death ); // death
imagettftext( $canvas, 20, -1, 110, 220, $black, $font, $reason ); // reason
$facebook->setFileUploadSupport(true);
//Create an album
$album_details = array(
'message'=> 'How will you die?',
'name'=> 'How will you die?'
);
$create_album = $facebook->api('/me/albums', 'post', $album_details);
//Get album ID of the album you've just created
$album_uid = $create_album['id'];
//Upload a photo to album of ID...
$file='img/'.$fbid.'.jpg'; //Example image file
$photo_details = array( 'message'=> 'Find...51', 'image' => '@'.realpath($file));
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
enter code here
ImageDestroy( $canvas );
header("Location: http://facebook.com".$fbid."&photoid=".$upphoto."")
?>
Well i am using this php code to make a facebook application.I uploaded the font Arial.ttfto the root directory of my website. But still i am showing the error- Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35. I tried changing the case,but i did'nt worked for me. Where i went wrong in this code ?
好吧,我正在使用此 php 代码制作 facebook 应用程序Arial.ttf。我将字体上传到我网站的根目录。但我仍然显示错误 - Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35。我尝试改变案例,但我没有为我工作。我在这段代码中哪里出错了?
回答by Michael Berkowski
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.
根据 PHP 使用的 GD 库的版本,当 fontfile 不以 / 开头时,.ttf 将附加到文件名,库将尝试沿着库定义的字体路径搜索该文件名。
This seems to imply that the fontfile should be an absolute path, and if it isn't, the function will append another .ttfonto the end of it.
这似乎意味着字体文件应该是一个绝对路径,如果不是,该函数将.ttf在其末尾附加另一个。
Specify the full path to the font file.
指定字体文件的完整路径。
$font = "/home/a2424901/public_html/Arial.ttf";
Or omit the .ttfand use the GDFONTPATH. The documentationrecommends the following:
或者省略.ttf并使用GDFONTPATH。 文档建议如下:
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";
回答by Magictallguy
To add on to user2724960's answer;
Changing the FontName to __DIR__ . '/graph/fonts/someFont.ttf'did it for me.
添加到 user2724960 的答案;更改 FontName__DIR__ . '/graph/fonts/someFont.ttf'为我做到了。
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")
不要忘记用你的字体文件名替换“ someFont”(默认:“Forgotte”)
回答by ?wie?u
My solve (works for me):
我的解决方案(对我有用):
realpath('here/is/right/path/to/font.ttf');
回答by Criss
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);
回答by Genki
On GoDaddy (shared hosting, Cpanel), I have to specify the path only afterthe domain:
在GoDaddy(共享主机,Cpanel)上,我只需要在域后指定路径:
My files are here:
我的文件在这里:
URL: http://example.com/assets/fonts/verdana/verdana.ttf
path: /home/content/123456/html/example/assets/fonts/verdana/verdana.ttf
PHP code which works:
有效的 PHP 代码:
$font = 'assets/fonts/verdana/verdana.ttf';
Using other values for the path did not work.
对路径使用其他值不起作用。
回答by Metalife
I had same problem. My font name was
我有同样的问题。我的字体名称是
Titr.TTF
滴定法
and i changed it to
我把它改成
Titr.ttf
滴定文件
and its worked perfectly.
它的工作完美。
回答by Mahdian
if you are using pChart use this:
如果您使用的是 pChart,请使用以下命令:
$myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));
回答by Sanjay
Please check for the font folder under Resources.
请检查资源下的字体文件夹。

