wrap and center text in gd and php -


i have line of text need wrap , center in gd image. using ttf font well. can give me assistance please?

i have managed text wrap doing following, need center:

function wrap($fontsize, $angle, $fontface, $string, $width){      $ret = "";      $arr = explode(' ', $string);      foreach ( $arr $word ){          $teststring = $ret.' '.$word;         $testbox = imagettfbbox($fontsize, $angle, $fontface, $teststring);         if ( $testbox[2] > $width ){             $ret.=($ret==""?"":"\n").$word;         } else {             $ret.=($ret==""?"":' ').$word;         }     }      return $ret; } 

to center both horizontally , vertically: half height imagettfbbox of whole text (with new lines) , substract half height of image ($start_x).

now split text new lines, create ttfbox every line , it's height ($h) , half width ($w). draw line starting half image width + $w , $start_x, add $h $start_x, repat until lines written.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -