-->

警告:imagettftext()[function.imagettftext]:找不到/开放字体在

2019-05-12 06:02发布

<?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."")
?>

好吧,我使用这个PHP代码,使Facebook的application.I上传的字体Arial.ttf到我的网站的根目录。 但我仍显示错误- Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35 。 我试图改变的情况下,但我对我did'nt工作。 我哪里错了这段代码?

Answer 1:

从文档

根据该GD库的PHP版本使用,当fontfile没有领先/时则.ttf将被附加到文件名开始,图书馆将尝试搜索沿库定义字体路径文件名。

这似乎暗示fontfile应该是绝对路径,如果不是,该函数将另一个附加.ttf到它的结束。

指定完整路径字体文件。

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

或者省略.ttf并使用GDFONTPATH 。 该文件提出以下建议:

在字体使用它下面的小技巧可以减轻包含的问题驻留在同一目录下的脚本很多情况下。

putenv('GDFONTPATH=' . realpath('.'));
$font = "Arial";


Answer 2:

要添加到user2724960的答案; 更改的字体名称,以__DIR__ . '/graph/fonts/someFont.ttf' __DIR__ . '/graph/fonts/someFont.ttf'为我做。

全行:

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

不要忘记,以取代“someFont”与您的字体文件的名称(默认:“Forgotte”)



Answer 3:

我的解决(我的作品):

realpath('here/is/right/path/to/font.ttf');


Answer 4:

如果你正在使用pChart使用:

$myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));


Answer 5:

我有同样的问题。 我的字体名称是

Titr.TTF

和我改成了

Titr.ttf

和它的完美。



Answer 6:

请查看下资源的字体文件夹。



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