note 117209 added to function.imagettftext

From: Date: Sat, 02 May 2015 14:15:55 +0000
Subject: note 117209 added to function.imagettftext
Groups: php.notes 
Request: Send a blank email to php-notes+get-202414@lists.php.net to get a copy of this message
Another way to wrap and center using wordwrap and learning the number of lines in the result of that wordwrap <?php $text="privet privet privet privet privet privet2 privet2 privet2 privet2 privet2 privet3"; $text=wordwrap($text, 35, "\n", TRUE); //setting the image header in order to proper display the image header("Content-Type: image/png"); //try to create an image $im = @imagecreate(460, 215) or die("Cannot Initialize new GD image stream"); //set the background color of the image $background_color = imagecolorallocate($im, 0x00, 0x00, 0x00); //set the color for the text $text_color = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); //adf the string to the image $font = "verdana.ttf"; $font_size = 20; $angle = 0; $splittext = explode ( "\n" , $text ); $lines = count($splittext); foreach ($splittext as $text) { $text_box = imagettfbbox($font_size,$angle,$font,$text); $text_width = abs(max($text_box[2], $text_box[4])); $text_height = abs(max($text_box[5], $text_box[7])); $x = (imagesx($im) - $text_width)/2; $y = ((imagesy($im) + $text_height)/2)-($lines-2)*$text_height; $lines=$lines-1; imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font, $text); } imagepng($im); imagedestroy($im); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 176.99.134.37 ---- Manual Page -- http://php.net/manual/en/function.imagettftext.php Edit -- https://master.php.net/note/edit/117209 Del: integrated -- https://master.php.net/note/delete/117209/integrated Del: useless -- https://master.php.net/note/delete/117209/useless Del: bad code -- https://master.php.net/note/delete/117209/bad+code Del: spam -- https://master.php.net/note/delete/117209/spam Del: non-english -- https://master.php.net/note/delete/117209/non-english Del: in docs -- https://master.php.net/note/delete/117209/in+docs Del: other reasons-- https://master.php.net/note/delete/117209 Reject -- https://master.php.net/note/reject/117209 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202414) next »