note 42229 deleted from function.imagettftext by aidan

From: Date: Mon, 20 Sep 2004 09:54:31 +0000
Subject: note 42229 deleted from function.imagettftext by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77010@lists.php.net to get a copy of this message
Note Submitter: chmouel at chmouel dot com ---- This is a simple function for wordwraping a string in a box most others one give as example on this site didn't work for me. NB: That i manually calculate the $font_space but there should be an automatical way to find what a font char (modulo the font size) take in pixels.. <?php $font_space = "6.5"; $string = "On sait comment Arthur Rimbaud, poète irrécusable entre sa quinzième et sa dix-neuvième année, se tut brusquement en pleine verve, courut le monde, fit du négoce et de l'exploration, se refusa de loin à ce renom d'artiste qui le sollicitait, et mourut à trente-sept ans après d'énormes labeurs inutiles."; $w = 242; $h = 165; $size = 12; $lpos = 5; $im = imagecreate($w, $h); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); $pos = $size;$space = 0;$s = ''; for ($i=0;$i < strlen($string);$i++) { if ($space >= ($w - $lpos)) { $ss = ''; $o = strrpos($s, " "); for ($j = 0; $j < $o; $j++) $ss .= $s[$j]; $i -= ((strlen($s) - $o) - 1); imagettftext($im, $size, 0, $lpos, $pos, $black, "./times.ttf", $ss); $s='';$space = 0;$pos += ($size * 1.3); } $s .= $string[$i]; $space += $font_space; } imagettftext($im, $size, 0, $lpos, $pos, $black, "./times.ttf", $s); header("Content-Type: image/jpeg"); imagejpeg($im); imagedestroy($im); ?>

« previous php.notes (#77010) next »