Hello, I'm new here, and I would like to ask a quick question.

I am using imagettftext() in order to make a simple drawing script, that will draw some simple text on an image. I have no problems with this when running the script on my PC using WAMP, however as soon as I transfer the script to my webserver I get the errors:

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/infinity/public_html/diamonds/imgaddtest.php on line 10

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/infinity/public_html/diamonds/imgaddtest.php on line 11

However, my fontfile(04B_09_.tff) is in the same folder as the script. I have tried using:

<?php
putenv('GDFONTPATH=' . realpath('.'));

$font = '04B_09_';
?>

Aswell, as recommended in the PHP Documentation, and I've tried some other methods on google, and it still does not function.

I am running php 5.2.9.

Thanks,
CodeDemon

    Also, make sure that you have not used include() to get to the script, and are therefore working in the wrong directory. Use getcwd() to verify...

      DaveRandom;10972956 wrote:

      have you tried

      $font = './04B_09_.ttf';

      ?

      I have tried that, in fact that is what I have in my script at the moment 😉

      DaveRandom;10972957 wrote:

      Also, make sure that you have not used include() to get to the script, and are therefore working in the wrong directory. Use getcwd() to verify...

      I am executing the function directly from the same file in which function is defined.

        I suggest doing

        print(getcwd());

        anyway, in case the hosting company has jailed/chrooted you in a non-sensicle way.

        What do you get from

        var_dump(file_exists($font));

        etc?

          Also try changing the name of you .ttf file. Maybe your getting screwed up by this change:

          PHP Manual wrote:

          5.2.0 - It is now possible to specify an hexadecimal entity in $text.

            DaveRandom;10972964 wrote:

            I suggest doing

            print(getcwd());

            anyway, in case the hosting company has jailed/chrooted you in a non-sensicle way.

            What do you get from

            var_dump(file_exists($font));

            etc?

            Hmmm I tried that and it returned false.

            I also tried the same thing, after re-naming the font, still getting false.

            I chmodded the file to 777 and I still got false....

            Interesting.

              Well that is definitely at least part of the problem, but how to resolve it is now in your hands - I can't really comment without playing with your actual server.

              At least you have something to go on - let us know how you get on 🙂

                DaveRandom;10972968 wrote:

                Well that is definitely at least part of the problem, but how to resolve it is now in your hands - I can't really comment without playing with your actual server.

                At least you have something to go on - let us know how you get on 🙂

                Do you think it could be something with my PHP configuration?

                Here is how its configured on my server:

                http://screensnapr.com/v/zqPwdU.png

                http://screensnapr.com/v/Fc6Yoe.png

                  Nothing out of the ordinary there (at least, that my less than expert eyes can spot), but I don't think any of that section relates to accessing external files from a script, that is more about how the PHP binary itself behaves.

                  What happens if you create a.n. other text file and file_exists() that?

                  If you can find the absolute canonical path of the .ttf file, try specifying it like that.

                  Maybe give the file a different extension? Long shot, but maybe the hosting company doen't like people using there own ttf files, no idea why that would be but I'm running out of ideas...

                    DaveRandom;10972974 wrote:

                    Nothing out of the ordinary there (at least, that my less than expert eyes can spot), but I don't think any of that section relates to accessing external files from a script, that is more about how the PHP binary itself behaves.

                    What happens if you create a.n. other text file and file_exists() that?

                    If you can find the absolute canonical path of the .ttf file, try specifying it like that.

                    Maybe give the file a different extension? Long shot, but maybe the hosting company doen't like people using there own ttf files, no idea why that would be but I'm running out of ideas...

                    I solved it! That was very strange... php didnt seem to like me using .ttf, however it worked with the extension .TTF that's interesting, because on my PC it would work with the extension in lowercase.

                    Anyways, thanks for your help!

                    -CodeDemon

                      CodeDemon wrote:

                      because on my PC it would work with the extension in lowercase

                      Bizarre. Windows is normally case-insensitive with all file names. A new note for the PHP manual page, methinks...

                        DaveRandom;10972976 wrote:

                        Bizarre. Windows is normally case-insensitive with all file names. A new note for the PHP manual page, methinks...

                        I totally agree 😉

                        Thanks again!

                          This probably has nothing to do with PHP at all and everything to do with the underlying file system.

                          Linux uses a case-sensitive filesystem. "FOOBAR" is not the same file as "foobar". Windows, however, uses a case-insensitive filesystem, meaning the previous statement is false.

                          Thus, if your font file was named '04B_09.TTF', then PHP was correct in reporting that './04B_09.ttf' did not exist.

                            Write a Reply...