im haveing problems with php_gd 2.0 and
ImageTTFText($im, 12, 0, 54, 43, $black, "C:/windows/fonts/tahomabd.ttf", $coolmon[0]["item_37"]);

it says it cant find/open the font, but this worked when i had php_gd 1 any suggestions 😕 😕

if theres another way of doing this, how and can you post a example thanks

[edit] or is there a way to make Php_Gd 1 write images at a higher color than 256 color 😕

    just worth a try: but have you tried using backslashes: \

    so change your path to:

    "C:\windows\fonts\tahomabd.ttf"

    and you still have permissions to access this font file, correct?

    -sridhar

      here's something i found at the php.net manual:

      saxon@bubibu.com
      26-Jun-2002 03:59

      for "could not find/open font"
      imagettftext doesn't work well with absolute path in Windows.
      And it seems still a bug in 4.2.1.

      Try using a relative path:

      ../../windows/fonts/font.ttf

      of course the .. levels depend on where your www directory is.

      -sridhar

        same thing.. (whats a relative path.. my files are in c:\program files\Apache Group\Apache\htdocs 😕 )

          Originally posted by divinatum
          (whats a relative path..)

          A path that specifies the location of a file or directory in terms of (i.e. "relative to" where you are now.)

          "C:\program files\Apache Group\Apache\htdocs\" is an absolute path. This Is Where The File Is. (It's full name and lineage - its pedigree, or whakapapa, if you will).

          "..\elsewhere\bar.txt" is a relative path. It doesn't mean anything without know where you are to start with. In your case, it's the location of the script. If that's in C:\program files\Apache Group\Apache\htdocs\, then "..\elsewhere\bar.txt" is up one level (to C:\program files\Apache Group\Apache\") and back down again to C:\program files\Apache Group\Apache\elsewhere\, which is where bar.txt should be found. In general, ".." moves you up one level closer to the root ("C:") and then you go back down again until you get to the directory you want.

          I'm guessing your font files are in c:\windows\fonts. If you don't want to copy the relevant font files over to the same directory as your scripts - the relative-path way of saying "the same directory" is just . - then

          C:\program files\Apache Group\Apache\htdocs\
          We need to go up four levels to get back to the root, then go down again through "windows" and "fonts".

          So the relative path is

          ........\windows\fonts\

          I sometimes work like this. Take the full pathname of the current directory and tack the relative path on the end. Each ..\ gobbles up one directory to its left and destroys itself in the process.

          C:\program files\Apache Group\Apache\htdocs\..\..\..\..\windows\fonts\
          C:\program files\Apache Group\Apache\..\..\..\windows\fonts\
          C:\program files\Apache Group\..\..\windows\fonts\
          C:\program files\..\windows\fonts\
          C:\windows\fonts\
          

          which is indeed where we should have ended up.

          For more information consult the help files that came with Windows, or do a search on the Web for tutorials on how to use files and directories.

          Now there's a startling lacuna. Probably brought about by excessive reliance on WIMP interfaces...

            Im posting this reply just becuas ei liek the nickname weedpacket.. thats a sweet ass nickname man!!!

              2 months later

              Originally posted by divinatum
              im haveing problems with php_gd 2.0 and
              ImageTTFText($im, 12, 0, 54, 43, $black, "C:/windows/fonts/tahomabd.ttf", $coolmon[0]["item_37"]);

              it says it cant find/open the font, but this worked when i had php_gd 1 any suggestions 😕 😕

              if theres another way of doing this, how and can you post a example thanks

              [edit] or is there a way to make Php_Gd 1 write images at a higher color than 256 color 😕

              I had the same problem and thanks to this threat (pointed out to me that it's a gd version problem) I found something that might help:

              In the PHP docu they write: Depending on which version of the GD library that PHP is using, when fontfile does not begin with a leading '/', '.ttf' will be appended to the filename and the the library will attempt to search for that filename along a library-defined font path....

              In clear text the command should work in GD2 like that:
              ImageTTFText($im, 12, 0, 54, 43, $black, "tahomabd", $coolmon[0]["item_37"]);

              Try it out, it worked for me on W2K/Apache1.3.26/PHP4.2.3/GD2 ... 😃

                a month later

                Thank you Foto50!! I've been banging my head off the wall for about 3 hours now trying to get this to work... and it turns out all I had to do was drop the ".ttf". Haha, boy do I feel like a dumb ass. At least it's working now.

                To everyone that's having the "Could not find/open font" problem, this is the key right here.

                Thanks again! 😃

                  22 days later

                  Actually, long file names wasn't what was causing my problem. The path I was using was c:/apache/htdocs/. It worked great as soon as I dropped the .ttf from the file name.

                    8 days later

                    The above alternatives did not provide a solution for me - believe because of IIS. Instead it took a file monitor to determine that GD/FreeType was looking in the c:\winnt\fonts directory no matter what format I specified for the font full pathname. The solution (for now) was to create c:\winnt\fonts directory and place copies of the ttf files there. In PHP I specify fonts by short name only "arial", "tahomabd" etc.

                    Server - Windows XP/IIS5.1
                    PHP - 4.2.3

                    jjj

                      2 months later

                      Wow, you are right. It looks in c:\winnt\fonts... which doesnt even exist on my system (Windows XP = c:\windows)

                      Heres a little func to make this painless as possible (bug STILL exists in php-4.3.0-win32

                      function isWin() {
                      static $isWin;
                      if (!isset($isWin))
                      $isWin = (substr(PHP_OS, 0, 3) == 'WIN');
                      return $isWin;
                      }
                      function getTTFfileName($fileName) {
                      $fileName = str_replace('\','/',$fileName);
                      if (!file_exists($fileName))
                      die ('File '.$fileName.' does not exist');

                      if (isWin()) {
                      	$winFileName = substr($fileName,strrpos($fileName,'/')+1);
                      	if (!file_exists('c:/winnt/fonts/'.$winFileName)) {
                      		if (!file_exists('c:/winnt/fonts')) {
                      			@mkdir ('c:/winnt');
                      			mkdir ('c:/winnt/fonts');
                      		}
                      		copy ($fileName,'c:/winnt/fonts/'.$winFileName);
                      	}
                      	return substr($winFileName,0,strlen($winFileName)-4);
                      } else {
                      	return (dirname($_SERVER["PATH_TRANSLATED"])."/".$fileName);
                      }

                      }

                        Write a Reply...