note 73346 added to function.imagestring

From: Date: Mon, 19 Feb 2007 02:00:18 +0000
Subject: note 73346 added to function.imagestring
Groups: php.notes 
Request: Send a blank email to php-notes+get-123566@lists.php.net to get a copy of this message
// Example of use... // This is a simple function to output text to an image // which is centered (as much as I want to do by eye) // and wrapped // Just remember that all the sizes are guessed // doesn't cut on the space (only on number of characters) // or change color of text, but this isn't for that... function imageCenterString( $imgw, $imgh, $image_text = '', $text_size=5 ) { $im = imagecreate( $imgw, $imgh ); // white background and blue text $bg = imagecolorallocate($im, 255, 255, 255); $textcolor = imagecolorallocate($im, 0, 0, 0); $t_h = $t_w = $t_x = $t_y = 0; $base_w =9; $base_h = 16; $m = 0.88; switch ( $text_size ) { case 1: $t_w = $base_w*pow(($m*.98),4); $t_h = $base_h*pow(($m*.98),4); break; case 2: $t_w = $base_w*pow($m,3); $t_h = $base_h*pow($m,3); break; case 3: $t_w = $base_w*pow($m,2); $t_h = $base_h*pow($m,2); break; case 4: $t_w = $base_w*$m; $t_h = $base_h*$m; break; case 5: $t_w = $base_w; $t_h = $base_h; break; default: if ( $text_size >= 5 ) // set to 5 { $t_w = $base_w; $t_h = $base_h; } if ( $text_size < 5 ) // set to 1 { $t_w = $base_w*pow(($m*.98),4); $t_h = $base_h*pow(($m*.98),4); } break; } $text_array = array(); $max = floor($imgw/$t_w); for( $i=0; strlen($image_text) > 0; $i += $max) { array_push($text_array, substr($image_text,0,$max)); if ( strlen($image_text) >= $max ) { $image_text = substr($image_text,$max); } else { $image_text = ''; } } $t_y = ($imgh/2) - ($t_h*count($text_array)/2); foreach ( $text_array as $text ) { $t_x = ($imgw/2)-($t_w*strlen($text)/2); imagestring($im, $text_size, $t_x, $t_y, $text, $textcolor); $t_y += $t_h; } // output the image header("Content-type: image/gpeg"); imagejpeg($im); } ---- Server IP: 69.147.83.197 Probable Submitter: 71.145.176.60 ---- Manual Page -- http://www.php.net/manual/en/function.imagestring.php Edit -- https://master.php.net/note/edit/73346 Del: integrated -- https://master.php.net/note/delete/73346/integrated Del: useless -- https://master.php.net/note/delete/73346/useless Del: bad code -- https://master.php.net/note/delete/73346/bad+code Del: spam -- https://master.php.net/note/delete/73346/spam Del: non-english -- https://master.php.net/note/delete/73346/non-english Del: in docs -- https://master.php.net/note/delete/73346/in+docs Del: other reasons-- https://master.php.net/note/delete/73346 Reject -- https://master.php.net/note/reject/73346 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123566) next »