PHP-GD make line height compatible across all fonts on text wrap -
ok, working on simple generator using jquery. user enters text of his/her choice, selects font, font-color , font-size. properties displayed on separate div in real-time (live preview).
i need save generated preview picture. that, utilize php gd library. works fine fonts, messed up.
in first image, looks alright sec image, line height messed up.
this php script using processes properties
<?php //width , height of desired image $width = 320; $height= 320; //create image specified height , width $main_img = imagecreate($width, $height); $mx = imagesx($main_img); $my = imagesy($main_img); //capture values form $main_text = $_post['rtext']; $main_text_size = $_post['rfsize']; $color = $_post['rcolor']; $mt_f = $_post['rfont']; $main_text_x = ($mx/2); // more code here //wrap text if text long $words = explode(' ', $main_text); $lines = array($words[0]); $currentline = 0; for($i = 1; $i < count($words); $i++) { $linesize = imagettfbbox($main_text_size, 0, $mt_f, $lines[$currentline] . ' ' . $words[$i]); if($linesize[2] - $linesize[0] < $mx) { $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, $mt_f, "$line"); $line_width = $line_box[0]+$line_box[2]; $line_height = $line_box[1]-$line_box[7]; $line_margin = ($mx-$line_width)/2; $line_y = (($line_height+12) * $line_count); imagettftext($main_img, $main_text_size, 0, $line_margin, $line_y, $main_text_color, $mt_f, $line); // increment y next line below previous line $line_count ++; } header("content-type: image/png"); //code download image ?> is there way can modify part of code wrap text accomodate fonts? automatically calculate line height based on font?
thanks, help appreciated
i found useful class @ phpclasses imagefittext.class.php http://www.phpclasses.org/browse/file/41869.html. found illustration script implemented using class http://www.phpclasses.org/browse/file/41870.html. wanted.
worked perfectly!!!1
php gd image-manipulation textwrapping
No comments:
Post a Comment