警告:imagettftext()[function.imagettftext]:在第35行的/home/a2424901/public_html/index.php中找不到/打开字体

前端之家收集整理的这篇文章主要介绍了警告:imagettftext()[function.imagettftext]:在第35行的/home/a2424901/public_html/index.php中找不到/打开字体前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<?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 );                         // 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,170,$birthday );        // birthday
imagettftext( $canvas,255,172,$death );           // death
imagettftext( $canvas,20,220,$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',$photo_details);


    enter code here



ImageDestroy( $canvas );

header("Location: http://facebook.com".$fbid."&photoid=".$upphoto."")
?>

好吧,我正在使用这个PHP代码制作一个facebook应用程序.我将字体Arial.ttf上传到我的网站的根目录.但我仍然显示错误 – 警告:imagettftext()[function.imagettftext]:无法在第35行的/home/a2424901/public_html/index.PHP中找到/打开字体.我尝试更改案例,但我做了’对我有用.我在这段代码中出错的地方?

解决方法

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.

这似乎意味着fontfile应该是一个绝对路径,如果不是,该函数会将另一个.ttf附加到它的末尾.

指定字体文件的完整路径.

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

或者省略.ttf并使用GDFONTPATH. The documentation建议如下:

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";
原文链接:https://www.f2er.com/html/231480.html

猜你在找的HTML相关文章