Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35
Asked Answered
W

10

24
<?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 am using this php code to make a facebook application.I uploaded the font Arial.ttfto the root directory of my website. But still i am showing the error- Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/a2424901/public_html/index.php on line 35. I tried changing the case,but i did'nt worked for me. Where i went wrong in this code ?

Wisnicki answered 28/4, 2012 at 19:10 Comment(0)
M
45

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.

This seems to imply that the fontfile should be an absolute path, and if it isn't, the function will append another .ttf onto the end of it.

Specify the full path to the font file.

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

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

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";
Moderation answered 28/4, 2012 at 19:16 Comment(0)
E
18

To add on to user2724960's answer; Changing the FontName to __DIR__ . '/graph/fonts/someFont.ttf' did it for me.

Full line:

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

Don't forget to replace "someFont" with the name of your font file (default: "Forgotte")

Edraedrea answered 7/12, 2013 at 9:20 Comment(1)
it works, thanks. I thought it was permission issue, but it's not.Immolation
E
11

My solve (works for me):

realpath('here/is/right/path/to/font.ttf');
Excepting answered 26/10, 2018 at 20:4 Comment(0)
S
10

I am also on XAMPP, apparently XAMPP does only support full directory path to the font. This code works both on Windows (XAMPP) and on our providers Linux server:

$dir= dirname(realpath(__FILE__));
$sep=DIRECTORY_SEPARATOR;   
$font =$dir.$sep.'arial.ttf';
imagettftext($thumb, $size, 0, $y_pos, $size, $textcolor, $font, $txt);

(assuming that your font file is in the same directory as your php file)

Snarl answered 12/11, 2020 at 15:31 Comment(0)
E
1

I had same problem. My font name was

Titr.TTF

and i changed it to

Titr.ttf

and its worked perfectly.

Eunuchoidism answered 11/7, 2014 at 21:43 Comment(0)
J
1

it worked for me : use 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);
Jilt answered 2/9, 2019 at 2:57 Comment(0)
A
0

if you are using pChart use this:

$myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));
Arvad answered 28/8, 2013 at 10:25 Comment(0)
C
0

On GoDaddy (shared hosting, Cpanel), I have to specify the path only after the domain:

My files are here:

URL:  http://example.com/assets/fonts/verdana/verdana.ttf
path:  /home/content/123456/html/example/assets/fonts/verdana/verdana.ttf

PHP code which works:

$font = 'assets/fonts/verdana/verdana.ttf';

Using other values for the path did not work.

Casie answered 13/4, 2020 at 0:30 Comment(0)
C
0

I came across the same issue while working on localhost (XAMPP).

My solution was:

// Set Correct Path to Font File
$fontPath='C:\xampp\htdocs\Adeplay\fonts\Tesox\tesox.ttf'; 
Cohort answered 26/6, 2020 at 10:6 Comment(0)
B
-6

Please check for the font folder under Resources.

Brother answered 11/6, 2014 at 16:3 Comment(1)
This should be a comment, not an answer.Nourish

© 2022 - 2024 — McMap. All rights reserved.