Shoutbox

TrueType Fonts in PHP - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: TrueType Fonts in PHP (/showthread.php?tid=21357)

TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 06:46 PM

I'm having problems with migrating my 'Now Playin'' to TrueType Font setting, but I'm having problems.

I used the methods explained in http://uk2.php.net/manual/en/function.imagettftext.php (thanks to fluffy_lobster) but they seemed pointless to my server (probably they don't have the needed libs).

Is there any workaround or another way to achieve it?


RE: TrueType Fonts in PHP by fluffy_lobster on 02-12-2004 at 07:17 PM

You might not have the ttf module installed on you server.

Make a php file just containing:

code:
<?php phpinfo(); ?>
and run it, and report back the third box, called Configure Command, and it'll tell you if you have that or any alternatives installed.
RE: TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 07:34 PM

--with-freetype-dir=/usr/include/freetype2 :S

What am I doing wrong?? ^o)

You saw how the script looked like, didn't you?

* KeyStorm is sure it's a stupid-programmer-error :dodgy:

btw: you don't need to be so explicit ('do a phpinfo' would've been enough ;))


RE: TrueType Fonts in PHP by fluffy_lobster on 02-12-2004 at 07:41 PM

that's the entire config?  that can't be right, there's not even gd there :|

what's the error you're getting?


RE: TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 07:44 PM

no, I just showed you the interesting part :P (of course there is GD, otherways you wouldn't see the image in my sig)
I'm not getting no error, because the image is created and destroyed after passing the function (ie, if there's an error it doesn't brake the execution)
As it's image/png i don't see the parser notices :P

(i'm trying it in html)


RE: TrueType Fonts in PHP by fluffy_lobster on 02-12-2004 at 07:49 PM

Well in that case, don't declare the image/php header until you get to outputting the actual image.  Is there nothing about ttf then in your phpinfo?


RE: TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 07:57 PM

huh, sorry: 'with-ttf=/usr/' and ''--enable-gd-imgstrttf'' I almost miss them.

code:
<?php
  //header("Content-type: image/jpeg");
  $im = imagecreate(400, 30);
  $white = imagecolorallocate($im, 255, 255, 255);
  $black = imagecolorallocate($im, 0, 0, 0);


  imagettftext($im, 20, 0, 10, 20, $black, "_sans",  "Testing... Omega: &amp;#937;");
               //I tried many common font names in font
  imagejpeg($im, 'test.png');
  imagedestroy($im);
?>
<img src=test.png border=1>


I have uploaded those two fonts from my font folder (maybe crappy idea):
/fonts/tahoma.ttf (apparently ClearType)
/fonts/decotype.ttf (apparently TT)
RE: TrueType Fonts in PHP by fluffy_lobster on 02-12-2004 at 08:09 PM

ah (I)

you have to upload a ttf font and refer to it.  So the font has to be specified "./fonts/tahoma.ttf"


RE: TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 08:33 PM

I did that already try this before, pointless... :( (I tried again now, btw)
Can I know which fonts are included in the library?


RE: TrueType Fonts in PHP by fluffy_lobster on 02-12-2004 at 08:37 PM

Well that's how you do it... do what I said so that it shows what error it's returning, then that might explain what's wrong.


RE: TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 08:47 PM

look at http://funmail.keystorm.net/MP!/test.php

The code is:

code:
<?php
  //header("Content-type: image/jpeg");
  $im = imagecreate(400, 30);
  $white = imagecolorallocate($im, 255, 255, 255);
  $black = imagecolorallocate($im, 0, 0, 0);

  // Replace path by your own font path
  imagettftext($im, 20, 0, 10, 20, $black, "./fonts/decotype.ttf",
  "Testing... Omega: &amp;#937;");
  imagejpeg($im, 'test.png');
  imagedestroy($im);
?>
<img src=test.png border=1>


(I tried /fonts/decotype.ttf aswell, as stated in the php doc-page you told me)
RE: TrueType Fonts in PHP by fluffy_lobster on 02-12-2004 at 08:55 PM

I just noticed your config sets the fonts path as /usr/include/freetype2 - maybe try adding that before the path?  Font files relative to the file you're running should work just as well though


RE: TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 09:02 PM

quote:
Originally posted by KeyStorm
imagejpeg($im, 'test.png');
This doesn't show anything either...

quote:
Originally posted by fluffy_lobster
/usr/include/freetype2
It's unlikely that it works... I don't have privileges to the user-root.
I mean there, which are the fonts installed by default in there by freetype? (I think I read somewhere some fonts were included)
RE: TrueType Fonts in PHP by WDZ on 02-12-2004 at 09:05 PM

quote:
when fontfile does not begin with a leading '/', '.ttf' will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.
That tells me this:

For custom fonts relative to the current dir, have a '/' as the first character (get rid of that dot). Otherwise (if you want to use a default font), no slash.
RE: TrueType Fonts in PHP by fluffy_lobster on 02-12-2004 at 09:09 PM

I'm not sure, it might be somewhere on their website at http://www.freetype.org/

Hmm, try uploading my IP sig as a test, to see whether it's a problem on your server or with the font you're trying to use


RE: TrueType Fonts in PHP by KeyStorm on 02-12-2004 at 09:34 PM

quote:
Originally posted by WDZ
For custom fonts relative to the current dir, have a '/' as the first character (get rid of that dot). Otherwise (if you want to use a default font), no slash.

quote:
Originally posted by KeyStorm
(I tried /fonts/decotype.ttf aswell, as stated in the php doc-page you told me)

quote:
Originally posted by KeyStorm
which are the fonts installed by default in there by freetype?

Thanks for your help, so far :)
RE: TrueType Fonts in PHP by bach_m on 02-12-2004 at 11:37 PM

quote:
Originally posted by KeyStorm
(I tried /fonts/decotype.ttf aswell, as stated in the php doc-page you told me)

to make it relative to the current point, if ur server is running linux, use ~/path.

thats because of the filesystem linux uses, where the top directory is /, and everything is below thatt (its kinda complicated...)