php - Wrapping text written on a image -


i want write wrapped text image php. here demo. if copy, paste , send text below demo notice lines distorted , there paragraph spaces must not there. looking code hours. couldn't understand problem. there me?

sample text:

lorem ipsum dolor sit amet, consectetur adipiscing elit. sed ut justo consectetur, cursus lorem vitae, accumsan lorem. cras eu odio vulputate, rhoncus dui vel, aliquam lorem. fusce scelerisque facilisis lacus, quis malesuada justo placerat nec. curabitur elementum mattis nisl, sed sodales mauris congue et. nunc velit mauris, accumsan dictum vitae, pellentesque luctus leo. maecenas in venenatis orci. suspendisse sed neque magna. praesent vitae sapien porttitor diam aliquam eleifend. maecenas lacinia elit non velit vehicula rutrum. sed ultricies mauris vitae dapibus tempor. praesent eros metus, euismod ut est eget, rhoncus iaculis lorem. ut aliquet dictum ligula lobortis cursus. sed mattis ante ut odio tincidunt venenatis. donec euismod quam sit amet velit tincidunt, ut convallis ligula tempor. quisque tincidunt elit sem, quis laoreet orci accumsan in.

$mx = imagesx($im);   // width of created image $my = imagesy($im);   // height of image  //text vars///////// $main_text = $text;   // $text variable comes directly form $main_text_size = 20; // $text font size  $words = explode(' ', $main_text); $lines = array($words[0]); $currentline = 0;      for($i = 1; $i < count($words); $i++)     {         $linesize = imagettfbbox($main_text_size, 0, $font, $lines[$currentline] . ' ' . $words[$i]);         if($linesize[2] - $linesize[0] < ($mx-20))         {             $lines[$currentline] .= ' ' . $words[$i];         }         else         {             $currentline++;             $lines[$currentline] = $words[$i];         }     }   $line_count = 1; // loop through lines , place them on image foreach ($lines $line) {     $line_box = imagettfbbox($main_text_size, 0, $font, "$line");     $line_height = $line_box[1]-$line_box[7];     $line_y = (($line_height+4) * $line_count);     imagettftext($im, $main_text_size, 0, 5, $line_y, $black, $font, $line);      // increment y next line below previous line     $line_count ++; }     imagepng($im, 'image.png'); imagedestroy($im); 


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -