2012-04-28 3 views
7
<?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 코드를 사용하고 있습니다. 내 웹 사이트의 루트 디렉토리에 Arial.ttf 글꼴을 업로드했습니다. 하지만 여전히 오류 - Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35을 표시하고 있습니다. 나는 사건을 바꾸려고했지만, 나는 나를 위해 일하지 않았다. 이 코드에서 어디서 잘못 되었습니까? fontFile에이 선도/다음 .TTF 파일 이름에 추가됩니다 라이브러리가 검색을 시도합니다로 시작하지 않는 경우, 사용하고있는 GD 라이브러리 PHP의 버전에 따라경고 : imagettftext() [function.imagettftext] : 줄에 /home/a2424901/public_html/index.php에서 열기/글꼴을 찾을 수 없습니다 (35)

답변

22

From the docs

라이브러리 정의 글꼴 경로를 따라 파일 이름.

이것은 fontfile이 절대 경로 여야한다는 것을 암시하는 것으로 보이며 그렇지 않은 경우 함수는 다른 .ttf을 끝에 추가합니다.

글꼴 파일의 전체 경로를 지정하십시오.

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

또는이 .ttf를 생략하고 GDFONTPATH을 사용합니다. The documentation은 다음을 권장합니다.

글꼴을 사용하는 스크립트와 동일한 디렉토리에있는 대부분의 경우 다음 트릭은 포함 문제를 완화합니다. 당신이 pChart이를 사용하여 사용하는 경우

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

:

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

는 user2724960의 대답에 추가하려면; FontName을 __DIR__ . '/graph/fonts/someFont.ttf'으로 변경하면 나에게 도움이되었습니다.

전체 라인 :

+0

감사합니다. 허가 문제라고 생각했지만 그렇지 않습니다. – arjunaaji

-4

글꼴 폴더에 있는지 확인하십시오

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

는 ("Forgotte"기본값) 글꼴 파일의 이름으로 "someFont"를 대체하는 것을 잊었다하지 마십시오 자원.

+1

이것은 대답이 아닌 주석이어야합니다. – Tay2510

0

동일한 문제가있었습니다. 내 글꼴 이름은

Titr.TTF

하고 있었고, 난

Titr.ttf

로 변경하고 완벽하게 일했다.