note 70486 added to function.imagestring

From: Date: Wed, 18 Oct 2006 21:47:37 +0000
Subject: note 70486 added to function.imagestring
Groups: php.notes 
Request: Send a blank email to php-notes+get-118708@lists.php.net to get a copy of this message
Here's a simple function for creating an aligned string which is cutted to match the space between $x1 and $x2 <?php function imagestringcutted($img,$font,$y,$x1,$x2,$text,$color,$align="center") { $fontwidth = imagefontwidth($font); $fullwidth = strlen($text) * $fontwidth; $maxwidth = $x2-$x1; $targetwidth = $fullwidth-(4*$fontwidth); if($fullwidth > $maxwidth) { for($i = 0; $i < strlen($text) AND ((strlen($text)-($i-4))*$fontwidth) > $targetwidth ;$i++) { } $text = substr($text,0,(strlen($text)-$i)-4)."..."; } if($align == "left") imagestring($img,$font,$x1,$y,$text,$color); elseif($align == "right") imagestring($img,$font,$x2 - ((strlen($text) * $fontwidth)),$y,$text,$color); else imagestring($img,$font,($x2-$x1)/ 2 - strlen($text) * $fontwidth / 2,$y,$text,$color); } ?> Usage: <?php imagestringcutted($img,$font,$y,$x1,$x2,$text,$color,$align); ?> Will create a string $text, which is cutted if it's too long to match between $x1 and $2, on $img with font $font and color $color at height $y and with align to $align. Hope it will help some people. Sorry for my bad English. ---- Server IP: 217.160.72.57 Probable Submitter: 80.171.28.145 ---- Manual Page -- http://www.php.net/manual/en/function.imagestring.php Edit -- https://master.php.net/note/edit/70486 Del: integrated -- https://master.php.net/note/delete/70486/integrated Del: useless -- https://master.php.net/note/delete/70486/useless Del: bad code -- https://master.php.net/note/delete/70486/bad+code Del: spam -- https://master.php.net/note/delete/70486/spam Del: non-english -- https://master.php.net/note/delete/70486/non-english Del: in docs -- https://master.php.net/note/delete/70486/in+docs Del: other reasons-- https://master.php.net/note/delete/70486 Reject -- https://master.php.net/note/reject/70486 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118708) next »