Jump to content
xisto Community
Sign in to follow this  
tehyev

Php And Gd

Recommended Posts

So, today I was trying out a tutorial on making a dynamic image using PHP. So i followed all the steps correctly, upload it to my site and I get there errors

Warning: imagettfbbox(): Could not find/open font in /home/tehyev/public_html/fortune.php on line 16
Warning: Cannot modify header information - headers already sent by (output started at /home/tehyev/public_html/fortune.php:16) in /home/tehyev/public_html/fortune.php on line 20

Warning: imagettftext(): Could not find/open font in /home/tehyev/public_html/fortune.php on line 25


Does anyone know how to fix it?

Share this post


Link to post
Share on other sites

what tutorial are you using? with the font error I assume you would need a font file that you are using and that should fix it. But if you can provide a link to the tutorial that will make the question easier to answer.

Share this post


Link to post
Share on other sites

It is VERY hard to determine what the possible error could be without seeing your actual script file. Try attaching it in the post.

But just for the fun, if you used the exact copy of the complete script, try making change to the following line:

Line #2

$font_file = $_SERVER['DOCUMENT_ROOT']."../path/verdana.ttf";

Note the double "period" in case you didn't place the font under the folder called "path". BTW you created a folder called "path" or other and change it accordingly?

Share this post


Link to post
Share on other sites
$font_file = $_SERVER['DOCUMENT_ROOT']."/path/verdana.ttf";

Well I looked at the coding I would believe that the error lies with this line. The path to the font file put the full path that leads to the font file and see if that works.

Share this post


Link to post
Share on other sites

It is VERY hard to determine what the possible error could be without seeing your actual script file. Try attaching it in the post.
But just for the fun, if you used the exact copy of the complete script, try making change to the following line:

Line #2

$font_file = $_SERVER['DOCUMENT_ROOT']."../path/verdana.ttf";

Note the double "period" in case you didn't place the font under the folder called "path". BTW you created a folder called "path" or other and change it accordingly?
Originally I followed the tutorial and typed everything in notepad, but it gave me a lot of errors so I tried that code. And I made a folder called "fonts" and uploaded Verdana to there, and changed the path accordingly.

@ Saint Michael, I tried putting the full path "home/tehyev/public_html/fonts/verdana.ttf" and it didn't work either.

Share this post


Link to post
Share on other sites

Well i used that in my old server and it used to work.Tap17 has a better version than that of my old server.
There is some error in your script.
Post it and we will find the error.

<?php// Set the static variables (discussed in step 3)$font_file = $_SERVER['DOCUMENT_ROOT']."/home/tehyev/public_html/fonts/Verdana.TTF";$font_size = 8;$y_start = 53;$angle = 0;$max_width = 300;// Retrieve random fortune from text file (discussed in step 2)$fortune_array = file("fortunes.txt");srand((double) microtime() * 10000000);$fortune = array_rand($fortune_array);// Calculate horizontal starting point for the text (discussed in step 3)$line_width = imagettfbbox($font_size, 0, $font_file, $fortune_array[$fortune]);$x_start = (($max_width - $line_width[2] - $line_width[0]) / 2) + 50;// Create the image resource and assign colors to variables (discussed in steps 1 and 5)header("Content-type: image/png");$im = imagecreatefrompng("blank.png");$red = imagecolorallocate($im, 255, 0, 0);// Write the text to the image (discussed in step 4)imagettftext($im, $font_size, $angle, $x_start, $y_start, $red, $font_file, $fortune_array[$fortune]);// Create and then destroy the image (discussed in steps 5 and 6)imagepng($im);imagedestroy($im);?>

Theres the script.

Share this post


Link to post
Share on other sites

Original first lines :

$font_file = $_SERVER['DOCUMENT_ROOT']."/home/tehyev/public_html/fonts/Verdana.TTF";$font_size = 8;
Change to:
echo $_SERVER['DOCUMENT_ROOT'];$font_file = $_SERVER['DOCUMENT_ROOT']."/home/tehyev/public_html/fonts/Verdana.TTF";echo $font_file;
Check that you aren't duplicating a folder name in there someplace.
I am guessing that you might need to knock some of the path from this part:
/home/tehyev/public_html/fonts/Verdana.TTF

Share this post


Link to post
Share on other sites

Original first lines :

$font_file = $_SERVER['DOCUMENT_ROOT']."/home/tehyev/public_html/fonts/Verdana.TTF";$font_size = 8;
Change to:
echo $_SERVER['DOCUMENT_ROOT'];$font_file = $_SERVER['DOCUMENT_ROOT']."/home/tehyev/public_html/fonts/Verdana.TTF";echo $font_file;
Check that you aren't duplicating a folder name in there someplace.
I am guessing that you might need to knock some of the path from this part:
/home/tehyev/public_html/fonts/Verdana.TTF
So that got rid of the two messages at the top. Now it has:

/home/tehyev/public_html/home/tehyev/public_html/fonts/Verdana.TTFWarning: Cannot modify header information - headers already sent by (output started at /home/tehyev/public_html/fortune.php:4) in /home/tehyev/public_html/fortune.php on line 21

How can I fix that?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.