FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » More with imagettfbbox(); absolute url not working?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
More with imagettfbbox(); absolute url not working? [message #173363] Tue, 05 April 2011 03:19 Go to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
I'm still working with imagettfbbox(). The problem I'm having now is
that I can't seem to refer to the TTF file unless it's in the actual
directory as the index.php file; if I give a relative or absolute
path, I'm getting an error:

Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open
font in /home/accountname/public_html/variables.php on line 152

For this system, I have a variables.php file, located at the /
public_html/ directory. This is the file that uses imagettfbbox(),
like so:

$home = "http://www.example.com";

define("F_SIZE", 9);

// This is the problem line, # 152 in the error
define("F_FONT", "arialbd.ttf");

function get_bbox($text) {
return imagettfbbox(F_SIZE, 0, F_FONT, $text);
}


Now, if I'm loading index.php that's in the same directory as
variables.php, then this works fine (obviously). In other directories,
though, it (obviously) can't find the arialbd.ttf file.

In all files, I'm including variables.php like so:

include "../variables.php";

I've tried the following variations, but still get the same errors:

// Found this recommendation somewhere
define("F_FONT", "./arialbd.ttf");

// URLs are supposed to be OK
define("F_FONT", "$home/arialbd.ttf");

// Using no variables, just type the URL straight in
define("F_FONT", "http://www.example.com/arialbd.ttf");

// Thought that a relative path would at least work
// on the second-level directories
define("F_FONT", "../arialbd.ttf");


Finally, I tried removing define(), and switching to global variables,
but had the same error:

$f_size = "9";
$f_font = "$home/arialbd.ttf";

function get_bbox($text) {
global $f_size;
global $f_font;

return imagettfbbox($f_size, 0, $f_font, $text);
}


Can you guys tell me the correct way to define the path to arialbd.ttf
here?

TIA,

Jason
Re: More with imagettfbbox(); absolute url not working? [message #173366 is a reply to message #173363] Tue, 05 April 2011 04:19 Go to previous messageGo to next message
Mr. B-o-B is currently offline  Mr. B-o-B
Messages: 42
Registered: April 2011
Karma: 0
Member
jwcarlton cried from the depths of the abyss...

> I'm still working with imagettfbbox(). The problem I'm having now is
> that I can't seem to refer to the TTF file unless it's in the actual
> directory as the index.php file; if I give a relative or absolute
> path, I'm getting an error:
>
> Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open
> font in /home/accountname/public_html/variables.php on line 152
>
> For this system, I have a variables.php file, located at the /
> public_html/ directory. This is the file that uses imagettfbbox(),
> like so:
>
> $home = "http://www.example.com";
>
> define("F_SIZE", 9);
>
> // This is the problem line, # 152 in the error
> define("F_FONT", "arialbd.ttf");
>
> function get_bbox($text) {
> return imagettfbbox(F_SIZE, 0, F_FONT, $text);
> }
>
>
> Now, if I'm loading index.php that's in the same directory as
> variables.php, then this works fine (obviously). In other directories,
> though, it (obviously) can't find the arialbd.ttf file.
>
> In all files, I'm including variables.php like so:
>
> include "../variables.php";
>
> I've tried the following variations, but still get the same errors:
>
> // Found this recommendation somewhere
> define("F_FONT", "./arialbd.ttf");
>
> // URLs are supposed to be OK
> define("F_FONT", "$home/arialbd.ttf");
>
> // Using no variables, just type the URL straight in
> define("F_FONT", "http://www.example.com/arialbd.ttf");
>
> // Thought that a relative path would at least work
> // on the second-level directories
> define("F_FONT", "../arialbd.ttf");
>
>
> Finally, I tried removing define(), and switching to global variables,
> but had the same error:
>
> $f_size = "9";
> $f_font = "$home/arialbd.ttf";
>
> function get_bbox($text) {
> global $f_size;
> global $f_font;
>
> return imagettfbbox($f_size, 0, $f_font, $text);
> }
>
>
> Can you guys tell me the correct way to define the path to arialbd.ttf
> here?
>
> TIA,
>
> Jason
>


Are you running this on a *nix or windows box?

If $fontfile is a Windows UNC path, it *must* start with //SERVER rather
than \\SERVER
Re: More with imagettfbbox(); absolute url not working? [message #173368 is a reply to message #173366] Tue, 05 April 2011 05:23 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> Are you running this on a *nix or windows box?
>
> If $fontfile is a Windows UNC path, it *must* start with //SERVER rather
> than \\SERVER

No, it's on Linux, with GD2 installed.
Re: More with imagettfbbox(); absolute url not working? [message #173369 is a reply to message #173363] Tue, 05 April 2011 07:17 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 05/04/2011 5:19, jwcarlton escribió/wrote:
> I'm still working with imagettfbbox(). The problem I'm having now is
> that I can't seem to refer to the TTF file unless it's in the actual
> directory as the index.php file; if I give a relative or absolute
> path, I'm getting an error:
>
> Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open
> font in /home/accountname/public_html/variables.php on line 152
>
> For this system, I have a variables.php file, located at the /
> public_html/ directory. This is the file that uses imagettfbbox(),
> like so:
>
> $home = "http://www.example.com";
>
> define("F_SIZE", 9);
>
> // This is the problem line, # 152 in the error
> define("F_FONT", "arialbd.ttf");
>
> function get_bbox($text) {
> return imagettfbbox(F_SIZE, 0, F_FONT, $text);
> }
>
>
> Now, if I'm loading index.php that's in the same directory as
> variables.php, then this works fine (obviously). In other directories,
> though, it (obviously) can't find the arialbd.ttf file.
>
> In all files, I'm including variables.php like so:
>
> include "../variables.php";
>
> I've tried the following variations, but still get the same errors:
>
> // Found this recommendation somewhere
> define("F_FONT", "./arialbd.ttf");
>
> // URLs are supposed to be OK
> define("F_FONT", "$home/arialbd.ttf");
>
> // Using no variables, just type the URL straight in
> define("F_FONT", "http://www.example.com/arialbd.ttf");
>
> // Thought that a relative path would at least work
> // on the second-level directories
> define("F_FONT", "../arialbd.ttf");
>
>
> Finally, I tried removing define(), and switching to global variables,
> but had the same error:
>
> $f_size = "9";
> $f_font = "$home/arialbd.ttf";
>
> function get_bbox($text) {
> global $f_size;
> global $f_font;
>
> return imagettfbbox($f_size, 0, $f_font, $text);
> }
>
>
> Can you guys tell me the correct way to define the path to arialbd.ttf
> here?

I think you've tried all combinations except absolute paths on *disc*:

define('F_FONT', '/home/accountname/public_html/arialbd.ttf')

Relative paths aren't practical because they are relative to the main
script's working directory and loading local files through the web
server is overkill.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: More with imagettfbbox(); absolute url not working? [message #173372 is a reply to message #173366] Tue, 05 April 2011 09:09 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/5/2011 12:19 AM, Mr. B-o-B wrote:
> jwcarlton cried from the depths of the abyss...
>
>> I'm still working with imagettfbbox(). The problem I'm having now is
>> that I can't seem to refer to the TTF file unless it's in the actual
>> directory as the index.php file; if I give a relative or absolute
>> path, I'm getting an error:
>>
>> Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open
>> font in /home/accountname/public_html/variables.php on line 152
>>
>> For this system, I have a variables.php file, located at the /
>> public_html/ directory. This is the file that uses imagettfbbox(),
>> like so:
>>
>> $home = "http://www.example.com";
>>
>> define("F_SIZE", 9);
>>
>> // This is the problem line, # 152 in the error
>> define("F_FONT", "arialbd.ttf");
>>
>> function get_bbox($text) {
>> return imagettfbbox(F_SIZE, 0, F_FONT, $text);
>> }
>>
>>
>> Now, if I'm loading index.php that's in the same directory as
>> variables.php, then this works fine (obviously). In other directories,
>> though, it (obviously) can't find the arialbd.ttf file.
>>
>> In all files, I'm including variables.php like so:
>>
>> include "../variables.php";
>>
>> I've tried the following variations, but still get the same errors:
>>
>> // Found this recommendation somewhere
>> define("F_FONT", "./arialbd.ttf");
>>
>> // URLs are supposed to be OK
>> define("F_FONT", "$home/arialbd.ttf");
>>
>> // Using no variables, just type the URL straight in
>> define("F_FONT", "http://www.example.com/arialbd.ttf");
>>
>> // Thought that a relative path would at least work
>> // on the second-level directories
>> define("F_FONT", "../arialbd.ttf");
>>
>>
>> Finally, I tried removing define(), and switching to global variables,
>> but had the same error:
>>
>> $f_size = "9";
>> $f_font = "$home/arialbd.ttf";
>>
>> function get_bbox($text) {
>> global $f_size;
>> global $f_font;
>>
>> return imagettfbbox($f_size, 0, $f_font, $text);
>> }
>>
>>
>> Can you guys tell me the correct way to define the path to arialbd.ttf
>> here?
>>
>> TIA,
>>
>> Jason
>>
>
>
> Are you running this on a *nix or windows box?
>
> If $fontfile is a Windows UNC path, it *must* start with //SERVER rather
> than \\SERVER

Incorrect. Windows boxes do not need UNC paths if they are on the same
machine, so you do NOT need to use //SERVER to access the file.

But in this case it makes no difference whether this is Windows or
Linux. His problem is accessing the file via relative path.

P.S. ////SERVER also works quite well where it is required.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: More with imagettfbbox(); absolute url not working? [message #173373 is a reply to message #173363] Tue, 05 April 2011 09:25 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/4/2011 11:19 PM, jwcarlton wrote:
> I'm still working with imagettfbbox(). The problem I'm having now is
> that I can't seem to refer to the TTF file unless it's in the actual
> directory as the index.php file; if I give a relative or absolute
> path, I'm getting an error:
>
> Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open
> font in /home/accountname/public_html/variables.php on line 152
>
> For this system, I have a variables.php file, located at the /
> public_html/ directory. This is the file that uses imagettfbbox(),
> like so:
>
> $home = "http://www.example.com";
>
> define("F_SIZE", 9);
>
> // This is the problem line, # 152 in the error
> define("F_FONT", "arialbd.ttf");
>
> function get_bbox($text) {
> return imagettfbbox(F_SIZE, 0, F_FONT, $text);
> }
>
>
> Now, if I'm loading index.php that's in the same directory as
> variables.php, then this works fine (obviously). In other directories,
> though, it (obviously) can't find the arialbd.ttf file.
>
> In all files, I'm including variables.php like so:
>
> include "../variables.php";
>
> I've tried the following variations, but still get the same errors:
>
> // Found this recommendation somewhere
> define("F_FONT", "./arialbd.ttf");
>
> // URLs are supposed to be OK
> define("F_FONT", "$home/arialbd.ttf");
>
> // Using no variables, just type the URL straight in
> define("F_FONT", "http://www.example.com/arialbd.ttf");
>
> // Thought that a relative path would at least work
> // on the second-level directories
> define("F_FONT", "../arialbd.ttf");
>
>
> Finally, I tried removing define(), and switching to global variables,
> but had the same error:
>
> $f_size = "9";
> $f_font = "$home/arialbd.ttf";
>
> function get_bbox($text) {
> global $f_size;
> global $f_font;
>
> return imagettfbbox($f_size, 0, $f_font, $text);
> }
>
>
> Can you guys tell me the correct way to define the path to arialbd.ttf
> here?
>
> TIA,
>
> Jason

Jason,

While theoretically it will work to access a font file this way, it will
only do so if the font file is accessible from the web; you won't be
able to place it in a directory outside of your web site (which is
really a better idea anyway). Additionally, when such an operation does
work, it requires an extra request to the web server, unnecessarily
increasing server load.

A much better way to access files on your server (and not just .ttf
files - it works for other files you wish to include, also) is to make
it relative to the root directory of your web site *on the file system*.

You could hard code this, but then you have to change it every time you
move the site to a new directory, change hosting companies, go from your
development machine to your production one, etc. Fortunately, there is
a value in the $_SERVER superglobal array which helps here.

Use $home=$_SERVER['DOCUMENT_ROOT'];

This will set $home to the root directory of your web server on the
disk. You can now access your file with:

$f_font = "$home/arialbd.ttf";

Or, even better, since this would not normally be accessed from the web
and if your web hosting company allows you to place files below the
websites root directory, you can place the file 1 level down, i.e. if
your web sites's home directory is /var/www/example/html, you could
place the file in /var/www/example and access it with

$f_font = "$home/../arialbd.ttf";

Or even in a subdirectory of it with

$f_font = "$home/../fonts/arialbd.ttf";



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: More with imagettfbbox(); absolute url not working? [message #173376 is a reply to message #173373] Tue, 05 April 2011 21:01 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> Use $home=$_SERVER['DOCUMENT_ROOT'];
>
> This will set $home to the root directory of your web server on the
> disk.  You can now access your file with:
>
> $f_font = "$home/arialbd.ttf";

I snipped a bunch here for the sake of brevity, but you guys nailed
it! Using the document_root path solved the issue.

Thanks, guys :-)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: OpenSSL support => disabled (install ext/openssl)
Next Topic: How to test if .php is using FastCGI?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 21:16:27 GMT 2024

Total time taken to generate the page: 0.02394 seconds