note 65691 deleted from function.imagettfbbox by cmb
| From: | cmb@php.net | Date: | Sun, 17 Nov 2019 08:53:02 +0000 |
| Subject: | note 65691 deleted from function.imagettfbbox by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213088@lists.php.net to get a copy of this message | ||
Note Submitter: james.logsdon at firesidemedia dot net
----
I've modified Nimja's function a little. It doesn't support line-breaks (didn't
need it in my script), but it's easy enough to add in.
<?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;
}
?>