警告:imagettftext()[function.imagettftext]:在第35行的/home/a2424901/public_html/index.php中找不到/打开字体 [英] Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35

查看:229
本文介绍了警告: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, 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应用程序.我将字体Arial.ttf上传到了我网站的根目录.但是我仍然显示错误-Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35.我试图改变情况,但没有为我工作.我在此代码中出错的地方?

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使用的GD库版本,如果fontfile不是以前导/开头,则.ttf将附加到文件名,并且库将尝试沿着库定义的字体路径搜索该文件名.

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.

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";

或省略.ttf并使用GDFONTPATH. 文档建议以下内容:

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";

这篇关于警告:imagettftext()[function.imagettftext]:在第35行的/home/a2424901/public_html/index.php中找不到/打开字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆