PDA

View Full Version : GD Wordwrap



Dentafrice1
27-12-2006, 08:56 PM
http://www.ffwbmarion.com/imagergd/trophy.php?name=Belacme&date=12-27-06&text=heyyaa%20trophy%20time%20yes%20it%20is..%20oh %20yes%20it%20is%20test

How can I get this to wrap to a new line?

I cant figure out the imagettfbox

Robbie
27-12-2006, 08:59 PM
Is this for H-R by any chance? :P

Dentafrice1
27-12-2006, 08:59 PM
Yes it is ;)

Robbie
27-12-2006, 09:00 PM
Yay more good features

EDIT: Use wordwrap() ?

Dentafrice1
27-12-2006, 09:02 PM
Gifts too :)

If only I could figure this out

Robbie
27-12-2006, 09:10 PM
Would this help
http://www.php.net/wordwrap

Dentafrice1
27-12-2006, 09:11 PM
No but thanks tho. I already tried that.

Its something to do with imagettfbox

Robbie
27-12-2006, 09:12 PM
You mean imagettfbbox?

Dentafrice1
27-12-2006, 09:13 PM
yea that :P

Robbie
27-12-2006, 09:15 PM
This was on php.net, helpful?


<?php

function imageWordWrapBBox ( $Text, $Width = 650, $FontSize = 10, $Font = './fonts/arial.ttf' )
{
$Words = split ( ' ', $Text );
$Lines = array ( );
$Line = '';

foreach ( $Words as $Word )
{
$Box = imagettfbbox ( $FontSize, 0, $Font, $Line . $Word );
$Size = $Box[4] - $Box[0];
if ( $Size > $Width )
{
$Lines[] = trim ( $Line );
$Line = '';
}
$Line .= $Word . ' ';
}
$Lines[] = trim ( $Line );

$Dimensions = imagettfbbox ( $FontSize, 0, $Font, 'AJLMYabdfghjklpqry019`@$^&*(,' );
$lineHeight = $Dimensions[1] - $Dimensions[5];

return array ( $lineHeight, $Lines, $lineHeight * count ( $Lines ) );
}

function imageWordWrap ( $Text, $Width, $Color, $X = 0, $Y = 0, $FontSize = 10, $Font = './fonts/arial.ttf' )
{
$Data = $this->imageWordWrapBBox ( $Text, $Width, $FontSize, $Font );

foreach ( $Data[1] as $Key => $Line )
{
$locX = $X;
$locY = $Y + ( $Key * $Data[0] );
imagettftext ( $this->Image, $FontSize, 0, $locX, $locY, $Color, $Font, $Line );
}

return $Data;
}
?>

Invent
27-12-2006, 10:17 PM
Grr I need to start looking into GD again.

I stopped using it when I just couldnt find out aligning of the text pmsl.

Probs something which is REALLY easy aswell -.-

Dentafrice1
27-12-2006, 10:18 PM
$arr = imagettfbbox(6.4, 0, $font, $text2);
$width = $arr[2] - $arr[0];
$x = imagesx($crop) - $width - $diff-21;



imagettftext($crop, 6.4, 0, $x, 70, $black, $font, stripslashes($text2));


Aligns text all the way right

like the name in this:
http://www.ffwbmarion.com/imagergd/trophy.php?name=Belacme&date=12-27-06&text=hey&#37;20yes%20trophys%20are%20here!

Invent
27-12-2006, 10:20 PM
Oo. Thanks ALOT Kevin (:

*hugglez*

Dentafrice1
27-12-2006, 10:21 PM
Try to find me word wrap PLZZZ

Invent
27-12-2006, 10:22 PM
Yah, Hokay.

Dentafrice1
27-12-2006, 10:24 PM
<?php

function imageWordWrapBBox ( $text, $Width, $FontSize, $Font)
{
$Words = split ( ' ', $Text );
$Lines = array ( );
$Line = '';

foreach ( $Words as $Word )
{
$Box = imagettfbbox ( $FontSize, 0, $Font, $Line . $Word );
$Size = $Box[4] - $Box[0];
if ( $Size > $Width )
{
$Lines[] = trim ( $Line );
$Line = '';
}
$Line .= $Word . ' ';
}
$Lines[] = trim ( $Line );

$Dimensions = imagettfbbox ( $FontSize, 0, $Font, 'AJLMYabdfghjklpqry019`@$^&*(,' );
$lineHeight = $Dimensions[1] - $Dimensions[5];

return array ( $lineHeight, $Lines, $lineHeight * count ( $Lines ) );
}
function imageWordWrap ( $Text, $Width, $Color, $X, $Y, $FontSize, $Font)
{
$Data = $this->imageWordWrapBBox ( $text, $Width, $FontSize, $Font );

foreach ( $Data[1] as $Key => $Line )
{
$locX = $X;
$locY = $Y + ( $Key * $Data[0] );
imagettftext ( $this->Image, $FontSize, 0, $locX, $locY, $Color, $Font, $Line );
}

return $Data;
}
$text = "hey";
$font = "Bold.ttf";
$url2 = "troph.gif";
$crop = imagecreatefromgif($url2);
$black = imagecolorallocate($crop, 127, 85, 43);
echo imageWordWrap($text, 650, $black, 0, 0, 6.4, $font);
?>


Fatal error: Call to a member function on a non-object in /home/ffwb/public_html/imagergd/test33.php on line 29

I get this

Invent
27-12-2006, 10:47 PM
Kevin could you help me

At: http://mini-i.fm/imager/pedestal_new.php?habbo=Jotters&mission=Testing the mission&badge=staff

I would like it to not go off the screen but automatically move the text to the left or whatever like in your version of the script.

Would you be able to help me on how to do this?

Invent
27-12-2006, 11:18 PM
Edit: Don't actually think it would help && ignore my above post, I coded it wrong. It now works

Want to hide these adverts? Register an account for free!