Warning: imagettftext () [function.imagettftext]: Could not find / open the font in / home / a 2424901 / public_html / index.php on line 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."") ?> 

Well, I use this php code to create a facebook application. I uploaded the Arial.ttf font to the root directory of my site. But still I am showing an error- Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35 . I tried to change things, but I did'nt worked for me. Where did I go wrong in this code?

+16
source share
7 answers

From the documents

Depending on which version of the GD PHP library is used, when the font file does not start with the leading / then .ttf will be added to the file name and the library will try to search for this file name in the specific font path library.

This seems to mean that the font file should be an absolute path, and if it isn't, the function will add another .ttf to the end.

Specify the full path to the font file.

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

Or omit .ttf and use GDFONTPATH . The documentation recommends the following:

In many cases, when the font is in the same directory as the script using it, the following trick will ease any inclusion issues.

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

To add to the user 2724960 the answer; Change the name of FontName to __DIR__ . '/graph/fonts/someFont.ttf' __DIR__ . '/graph/fonts/someFont.ttf' did this for me.

Full line:

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

Remember to replace " someFont " with the name of your font file (default: "Forgotte")

+9
source

My solution (works for me):

 realpath('here/is/right/path/to/font.ttf'); 
+3
source

if you use pChart use this:

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

I had the same problem. My font name was

Titr.TTF

and I changed it to

Titr.ttf

and it worked great.

0
source

it worked for me to use the absolute path

 $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
source

Check the font folder in the Resources section.

-6
source

All Articles