web-dev-qa-db-ja.com

警告:imagettftext()[function.imagettftext]:/home/a2424901/public_html/index.phpの35行目でフォントを見つけられませんでした/開けませんでした

_<?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_を自分のWebサイトのルートディレクトリにアップロードしました。しかし、それでもエラー-Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35を示しています。ケースを変えてみましたが、うまくいきませんでした。このコードでどこが間違っていましたか?

16
Nishant Ghodke

ドキュメントから

Gdライブラリのバージョンに応じてPHPが使用している場合、fontfileが先頭の/で始まっていない場合、.ttfがファイル名に追加され、ライブラリはそのファイル名を一緒に検索しようとします。ライブラリ定義のフォントパス。

これは、フォントファイルが絶対パスでなければならないことを意味しているようです。そうでない場合、関数はその末尾に別の.ttfを追加します。

フォントファイルのフルパスを指定してください。

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

または、.ttfを省略してGDFONTPATHを使用します。 ドキュメント は以下を推奨します:

フォントがそれを使用するスクリプトと同じディレクトリにある多くの場合、次のトリックはインクルードの問題を軽減します。

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

User2724960の回答に追加するには、 FontNameを__DIR__ . '/graph/fonts/someFont.ttf'に変更すると、それができました。

フルライン:

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

"someFont"をフォントファイルの名前に置き換えることを忘れないでください(デフォルト: "Forgotte")

9
Magictallguy

私の解決(私のために働く):

realpath('here/is/right/path/to/font.ttf');
5
Świeżu

pChartを使用している場合は、これを使用します。

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

それは私のために働きました:絶対パスを使用してください

$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);
0
Criss

同じ問題がありました。私のフォント名は

Titr.TTF

そして私はそれを

Titr.ttf

そしてそれは完全に働いた。

0
Metalife