Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

where are the fonts filed away for imagettftext() function

images php coding issues or problems here.

Moderators: macek, egami, gesf

where are the fonts filed away for imagettftext() function

Postby fishermanjuice » Fri Apr 28, 2006 4:52 pm

I am trying to load the fonts from my GD libraray and I have no idea what to type into the path. Where does that usually get saved when you load PHP? Any examples of the line pointing to the PATH that actually work? I keep getting the "failed to find/open the font" error. :?
fishermanjuice
New php-forum User
New php-forum User
 
Posts: 50
Joined: Fri Apr 28, 2006 4:47 pm
Location: Pittsburgh, PA

Postby Coditor » Sun Apr 30, 2006 1:10 am

Afaik fonts are not included with GD. You should upload TTF fonts yourself - anywhere you like - and specify the path to them in your PHP script.

Coditor
Coditor
New php-forum User
New php-forum User
 
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands

Still cant find/open fonts

Postby fishermanjuice » Tue May 02, 2006 5:34 pm

I can't seem to get the code to identify the path correctly. I am using the following to try and get it to work. Am I typing the path incorrectly?

Code: Select all
<?php
//create the canvas
$myImage = imagecreate(150,150);

//set up some colors
$white = imagecolorallocate ($myImage, 255, 255, 255);
$green = imagecolorallocate ($myImage, 50, 150, 50);
$blue = imagecolorallocate ($myImage, 0, 0, 100);
$lt_red = imagecolorallocate($myImage, 255, 150, 150);
$lt_green = imagecolorallocate($myImage, 100, 200, 100);
$lt_blue = imagecolorallocate($myImage, 50, 50, 150);

//display some text
imagettftext($myImage, 0, 10, 0, 0, 50, $white, 'C:\Program Files\ApacheGroup\Apache2\htdocs\Fonts', 'text to display');
?>


I downloaded the TTF files into a folder called 'Fonts' in the document root of the webserver using the path above. What am I doing wrong?

Cheers!
Justin
fishermanjuice
New php-forum User
New php-forum User
 
Posts: 50
Joined: Fri Apr 28, 2006 4:47 pm
Location: Pittsburgh, PA

Postby Coditor » Wed May 03, 2006 2:51 am

The path should contain the name of the fontfile as well.

Eg:
imagettftext($myImage, 0, 10, 0, 0, 50, $white, 'C:\Program Files\ApacheGroup\Apache2\htdocs\Fonts\Arial.ttf', 'text to display');

Coditor
Coditor
New php-forum User
New php-forum User
 
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands

Postby fishermanjuice » Wed May 03, 2006 6:46 am

I added the Arial.ttf to the end of the path, there is an Arial.ttf font file in the folder too. Still no go. Is there a php.ini setting that I am missing?
fishermanjuice
New php-forum User
New php-forum User
 
Posts: 50
Joined: Fri Apr 28, 2006 4:47 pm
Location: Pittsburgh, PA

The code that I have where imagettftext() is failing

Postby fishermanjuice » Wed May 03, 2006 7:19 am

Why doesn't this code work?! I did check the .ini settings. The GD library is enabled with FreeType.

Code: Select all
<?php
//create the canvas
$myImage = imagecreate(300,150);

//set up some colors
$white = imagecolorallocate ($myImage, 255, 255, 255);
$green = imagecolorallocate ($myImage, 50, 150, 50);
$blue = imagecolorallocate ($myImage, 0, 0, 100);

//set the path to fonts
$font_path = "C:/WINDOWS/Fonts/Arial.ttf";

//insert text to image
imagettftext($myImage, 5, 0, 0, 0, 50, $blue, $font_path, 'texttoadd');

//output the image to the browser
header ("Content-type: image/png");
imagePng($myImage);

//clean up after myself
imagedestroy($myImage);
?>


The exact reply that I get is the following

Warning: imagettftext() [function.imagettftext]: Could not find/open font in C:\Program Files\Apache Group\Apache2\htdocs\imagettftest.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\imagettftest.php:14) in C:\Program Files\Apache Group\Apache2\htdocs\imagettftest.php on line 17
‰PNG  IHDR,–5]A PLTEÿÿÿ2–2dyXH "IDATxœíÁ1 õOm >,ˆžÖÿdIEND®B`‚
fishermanjuice
New php-forum User
New php-forum User
 
Posts: 50
Joined: Fri Apr 28, 2006 4:47 pm
Location: Pittsburgh, PA

Postby Coditor » Wed May 03, 2006 10:24 am

imagettftext requires the following parameters:

resource image, float size, float angle, int x, int y, int color, string fontfile, string text

You're calling it like:
Code: Select all
imagettftext($myImage, 5, 0, 0, 0, 50, $blue, $font_path, 'texttoadd');

There is one number too much, so $blue is now the value your providing for the font. Try this:
Code: Select all
imagettftext($myImage, 5, 0, 0, 50, $blue, $font_path, 'texttoadd');

(assuming that you want y to be 50)

Coditor
Coditor
New php-forum User
New php-forum User
 
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands

Thank you Coditor!

Postby fishermanjuice » Wed May 03, 2006 10:10 pm

My gosh. I wasted hours on that problem lol! I guess that's a noob programer for ya! Thanks Coditor!

Cheers!

Justin
fishermanjuice
New php-forum User
New php-forum User
 
Posts: 50
Joined: Fri Apr 28, 2006 4:47 pm
Location: Pittsburgh, PA

Re: where are the fonts filed away for imagettftext() functi

Postby alexalexalexalex » Wed Aug 25, 2010 6:13 am

Hello,
I found a great tutorial of how to learn php in just 17 hours. :D Its awesome! :P You should check it out! this is the link:
http://8ea82rl0mfsupbdeseqkgfmleq.hop.clickbank.net/
alexalexalexalex
New php-forum User
New php-forum User
 
Posts: 3
Joined: Wed Aug 25, 2010 5:57 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron