PHP - wrapping ttf fonts in GD

Started by Parham, September 04, 2003, 08:16:18 PM

Previous topic - Next topic

Parham

the title is pretty self-explanatory.  I know there exist functions which allow you to wrap the normal builtin GD fonts (hell I use it in my sig), but I was wondering if anything like it existed when fonts were used from the outside (ttf fonts).  I haven't been able to find a function which wraps ttf fonts within certain limitations.

[Unknown]

http://www.php.net/function.imagettftext

[edit]Ooops, you meant wrapping.  Why not do it yourself?  That's the way I always had to do it... I didn't even know GD had wrapping...[/edit]

-[Unknown]

Aquilo

don't none of it have a function to it, you have to do it with php.

something like this:

$text = wordwrap($text, 40, "\n", 1);
$lines = explode("\n", $text);

// then some for each stuff to get your bouncing box
// or just print it out

Parham

Quote from: [Unknown] on September 04, 2003, 08:44:39 PM
http://www.php.net/function.imagettftext

[edit]Ooops, you meant wrapping.  Why not do it yourself?  That's the way I always had to do it... I didn't even know GD had wrapping...[/edit]


function ImageStringWrap($image, $font, $x, $y, $text, $color, $maxwidth) {
  $fontwidth = ImageFontWidth($font);
  $fontheight = ImageFontHeight($font);

  if ($maxwidth != NULL) {
    $maxcharsperline = floor($maxwidth / $fontwidth);
    $text = wordwrap($text, $maxcharsperline, "\n", 1);
  }

  $lines = explode("\n", $text);
  foreach ($lines as $line) {
    ImageString($image, $font, $x, $y, $line, $color);
    $y += $fontheight;
  }
}


I found it somewhere on the net and it'll wrap the builtin fonts

-[Unknown]

Aquilo that's what I had in mind, except it might not work with weird wide fonts... That's actually what I had in mind :), but how do you print if you don't know the height of the font... etc etc.  I guess it all depends on the font you use and it takes a lot of manual work.  I was looking for something universal :P (high hopes i know)

Aquilo

"it takes a lot of manual work"-

that's what I had to do when I started using ttf text in my images
but the bouncing box helps alot!

Parham

Quote from: Aquilo on September 04, 2003, 11:06:36 PM
"it takes a lot of manual work"-

that's what I had to do when I started using ttf text in my images
but the bouncing box helps alot!

bouncing box... more info?

Aquilo

imagettfbbox()
http://us2.php.net/manual/en/function.imagettfbbox.php

there are a few good examples for it's use and good ideas for working with it - one I was thinking of was taking the widest letter "m" and using Width & Height as the font Width size for the maximum characters on a line routine!

Parham


Advertisement: