image - How to make word wrap limited by stringlength in pixels (PHP) -


im trying sign image gd.

i have line of text, may this: "this long line of text"

if use 60th font, wont fit in image, need how wordwrap

now i'm using loop doing word wrap limited number of symbols , adding text image line line..

$words = explode(" ", $text); if (strlen($words[0]) > 20)     $output = substr($words[0], 0, 20); else {     $output = array_shift($words);     while (strlen($output . " " . $words[0]) <= 20) {         $output .= " " . array_shift($words);     } } $text = $str2 = substr($text, strlen($output));  list($left,, $right) = imageftbbox($font_sizet, 0, $font_path, $output); $width = $right - $left; $leftx = (740 - $width) / 2; $topy = (560 + $i * 30); imagettftext($img, $font_sizet, 0, $leftx, $topy, $white, $font_path, $output); 

the problem script if first letters going "wwwwwwwwwww", image fit 10 symbols... , if first letters going "llllllllllll" text short.

the width of text cant determine using line:

list($left,, $right) = imageftbbox( $font_sizet, 0, $font_path, $output); $width = $right - $left; 

<- think somehow can use $width in loop compare maxlength

how can change limiting number of symbols limiting number of pixels (lets say, want line no longer 300px)?


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -