草庐IT

php - 警告 : imagettftext() [function. imagettftext] : Could not find/open font in/home/a2424901/public_html/index. php 第 35 行

coder 2023-06-15 原文

<?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。我尝试改变案例,但我没有为我工作。我在这段代码中哪里出错了?

最佳答案

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.

这似乎暗示字体文件应该是绝对路径,如果不是,函数将在其末尾附加另一个 .ttf

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

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

或者省略 .ttf 并使用 GDFONTPATHThe 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";

关于php - 警告 : imagettftext() [function. imagettftext] : Could not find/open font in/home/a2424901/public_html/index. php 第 35 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10366679/

有关php - 警告 : imagettftext() [function. imagettftext] : Could not find/open font in/home/a2424901/public_html/index. php 第 35 行的更多相关文章

  1. ruby - Sinatra set cache_control to static files in public folder编译错误 - 2

    我不知道为什么,但是当我设置这个设置时它无法编译设置:static_cache_control,[:public,:max_age=>300]这是我得到的syntaxerror,unexpectedtASSOC,expecting']'(SyntaxError)set:static_cache_control,[:public,:max_age=>300]^我只想将“过期”header设置为css、javaascript和图像文件。谢谢。 最佳答案 我猜您使用的是Ruby1.8.7。Sinatra文档中显示的语法似乎是在Ruby1.

  2. ruby - 在 Ruby 中创建按公共(public)键值分组的新哈希 - 2

    假设我有一个在Ruby中看起来像这样的哈希:{:ie0=>"Hi",:ex0=>"Hey",:eg0=>"Howdy",:ie1=>"Hello",:ex1=>"Greetings",:eg1=>"Goodday"}有什么好的方法可以将它变成如下内容:{"0"=>{"ie"=>"Hi","ex"=>"Hey","eg"=>"Howdy"},"1"=>{"ie"=>"Hello","ex"=>"Greetings","eg"=>"Goodday"}} 最佳答案 您要求一个好的方法来做到这一点,所以答案是:一种您或同事可以在六个月后理解

  3. ruby - "public/protected/private"方法是如何实现的,我该如何模拟它? - 2

    在ruby中,你可以这样做:classThingpublicdeff1puts"f1"endprivatedeff2puts"f2"endpublicdeff3puts"f3"endprivatedeff4puts"f4"endend现在f1和f3是公共(public)的,f2和f4是私有(private)的。内部发生了什么,允许您调用一个类方法,然后更改方法定义?我怎样才能实现相同的功能(表面上是创建我自己的java之类的注释)例如...classThingfundeff1puts"hey"endnotfundeff2puts"hey"endendfun和notfun将更改以下函数定

  4. ruby - private、protected 和 public 的范围 - 2

    在Ruby类定义中,private关键字在以下场景中的作用域是什么:classFoodefbar_publicputs"public"endprivatedefbar_privateputs"private"enddefbar_public_2puts"anotherpublic"endendprivate是否只作用于bar_private?还是在bar_public_2上? 最佳答案 在您的例子中,bar_private和bar_public_2都是私有(private)的。那是因为这两种方法都在private关键字的“范围内”。

  5. ruby - 在 Ruby 模块中定义公共(public)方法? - 2

    我一定是犯了n00b错误。我编写了以下Ruby代码:moduleFoodefbar(number)returnnumber.to_s()endendputsFoo.bar(1)测试.rb:6:in':undefinedmethodbar'forFoo:Module(NoMethodError)我想在名为Foo.bar的模块上定义一个方法。但是,当我尝试运行代码时,出现未定义方法错误。我做错了什么? 最佳答案 你可以这样做:moduleFoodefself.bar(number)number.to_sendendputsFoo.bar

  6. ruby-on-rails - 这个 C 和 PHP 程序员如何学习 Ruby 和 Rails? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它

  7. ruby - 是否可以动态检查方法可见性范围(私有(private)/公共(public)/ protected )? - 2

    如thisanswer中所述,在Ruby2.1或更高版本中,此代码:classSimpleTestprivatedefine_method:foodo42endend将定义foo作为SimpleTest的私有(private)方法实例。(在Ruby2.0和更早版本中,它不会是私有(private)的。)但是,我希望做一些不那么琐碎的事情。我想定义一个类可以扩展的DSL,并希望DSL在内部定义的方法尊重调用上下文的私有(private)/protected可见性。这可能不是很清楚,所以这里有一个例子:moduleDsldefhas_a(name)define_methodnamedo42

  8. ruby-on-rails - Rails 不呈现 public/index.html 文件;浏览器中的空白页面 - 2

    当我将我的Rails+React应用程序部署到Heroku时,我遇到了问题。React客户端位于Rails应用程序的client/目录中。由于使用了react-router,Rails服务器需要知道从React构建中渲染index.html。当我在Heroku上部署客户端时,脚本将内容从client/build/.复制到Rails应用程序的public/目录。现在问题来了:当我的路由检测到类似example.com/about的路径时,它会尝试呈现public/index.html。方法如下:deffallback_index_htmlrenderfile:"public/index.

  9. ruby-on-rails - 我日志中的 [1m[35m] 是什么,我该如何让它消失? - 2

    如果这个问题已经得到回答,我提前道歉。我一直在尝试在Google和StackOverflow上搜索此内容,但由于我的搜索查询中包含标点符号,因此搜索引擎往往会对其进行修改并给出无意义的结果。在我的rails应用程序(rails3.2.11,ruby1.9.3)中,我的日志经常是这样的:StartedGET"/apply/contact"for127.0.0.1at2013-01-2917:35:21-0600ProcessingbyJobApplicationsController#showasHTMLParameters:{"id"=>"contact"}[1m[36mJobAppl

  10. ruby-on-rails - 如何在公共(public)事件中设置收件人ID - 2

    我正在查看公共(public)事件GemRailscastVid。(http://railscasts.com/episodes/406-public-activity)我当前的数据库查找/存储除了recipient_id之外的所有内容....它显示为nil#我希望recipient_id是正在执行操作的用户....例如如果我喜欢Tom的帖子......我希望Tom的ID成为recipient_id,我将成为owner_id。我目前已经设置了一个收件人ID....使用我的LikesController中的代码....但它只将收件人ID设置为当前用户....这不是我想要的:(喜欢Cont

随机推荐