2012-04-28 17 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."") 
?> 

Bueno, yo estoy usando el código php para hacer una aplicación de Facebook. Cargué la fuente Arial.ttf en el directorio raíz de mi sitio web. Pero aún estoy mostrando el error- Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35. Traté de cambiar el caso, pero no funcionó para mí. ¿Dónde me equivoqué en este código?Advertencia: imagettftext() [function.imagettftext]: No se pudo encontrar/fuente abierta en /home/a2424901/public_html/index.php en la línea 35

Respuesta

22

From the docs

Dependiendo de la versión de la librería GD de PHP está usando, cuando fontfile no comienza con un líder/.ttf continuación se anexará al nombre de archivo y la biblioteca intentará buscar ese nombre de archivo a lo largo de una ruta de fuente definida por la biblioteca.

Esto parece implicar que el fontfile debe ser una ruta absoluta, y si no lo es, la función añadirá otro .ttf sobre el extremo de la misma.

Especifique la ruta completa al archivo de fuente.

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

u omitir la .ttf y utilizar el GDFONTPATH. The documentation recomienda lo siguiente:

En muchos casos en los que una fuente reside en el mismo directorio que el script con el siguiente truco que aliviará incluyen problemas.

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

si está utilizando pChart utilizar este:

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

para añadir a la respuesta de user2724960; Cambiando FontName a __DIR__ . '/graph/fonts/someFont.ttf' lo hizo por mí.

línea completa:

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

No se olvidó de reemplazar "someFont" con el nombre de su archivo de fuente (por defecto: "Forgotte")

+0

funciona, gracias. Pensé que era un problema de permiso, pero no lo es. – arjunaaji

-4

Por favor, compruebe la carpeta de fuentes bajo Recursos.

+1

Esto debería ser un comentario, no una respuesta. – Tay2510

0

Tuve el mismo problema. Mi nombre de la fuente era

Titr.TTF

y me lo cambió a

Titr.ttf

y su funcionó a la perfección.

Cuestiones relacionadas