General Community > Scripting Help
PHP - wrapping ttf fonts in GD
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:
--- Code: ---$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
--- End code ---
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]
--- Code: ---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;
}
}
--- End code ---
I found it somewhere on the net and it'll wrap the builtin fonts
-[Unknown]
--- End quote ---
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!
Navigation
[0] Message Index
[#] Next page
Go to full version