note 65691 added to function.imagettfbbox

From: Date: Fri, 05 May 2006 20:32:08 +0000
Subject: note 65691 added to function.imagettfbbox
Groups: php.notes 
Request: Send a blank email to php-notes+get-110662@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 69.15.171.66 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php Edit -- http://master.php.net/note/edit/65691 Del: integrated -- http://master.php.net/note/delete/65691/integrated Del: useless -- http://master.php.net/note/delete/65691/useless Del: bad code -- http://master.php.net/note/delete/65691/bad+code Del: spam -- http://master.php.net/note/delete/65691/spam Del: non-english -- http://master.php.net/note/delete/65691/non-english Del: in docs -- http://master.php.net/note/delete/65691/in+docs Del: other reasons-- http://master.php.net/note/delete/65691 Reject -- http://master.php.net/note/reject/65691 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110662) next »