note 75479 added to function.imagettfbbox

From: Date: Fri, 01 Jun 2007 07:07:22 +0000
Subject: note 75479 added to function.imagettfbbox
Groups: php.notes 
Request: Send a blank email to php-notes+get-127096@lists.php.net to get a copy of this message
It took me some time to make full use of imagettfbbox. Hopefully the following function makes it much easier to use for others. <?php function convertBoundingBox ($bbox) { if ($bbox[0] >= -1) $leftOfBasepoint = -abs($bbox[0] + 1); else $leftOfBasepoint = abs($bbox[0] + 2); $rightOfBasepoint = abs($bbox[2] - $bbox[0]); if ($bbox[0] < -1) $rightOfBasepoint = abs($bbox[2]) + abs($bbox[0]) - 1; $aboveBasepoint = abs($bbox[5] + 1); $height = abs($bbox[7]) - abs($bbox[1]); if ($bbox[3] > 0) $height = abs($bbox[7] - $bbox[1]) - 1; $width = $leftOfBasepoint + $rightOfBasepoint; $belowBasepoint = $height - $aboveBasepoint; return array( 'width' => $width, 'height' => $height, 'leftOfBasepoint' => $leftOfBasepoint, 'rightOfBasepoint' => $rightOfBasepoint, 'aboveBasepoint' => $aboveBasepoint, 'belowBasepoint' => $belowBasepoint ); } ?> Thanks goes to mike at mikeleigh dot com for providing the core of this function. Remember, the basepoint is the x, y coords you use to draw text with imagettftext. A useful thing to do is take a string like... ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890 ...and use the "aboveBasepoint" value for the height of your font. Now you can draw lines and use "the height of your font * leading" as the distance between lines of text, where leading is a number like 1.45 (for 45% leading). ---- Server IP: 64.71.164.2 Probable Submitter: 67.161.110.125 ---- Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php Edit -- https://master.php.net/note/edit/75479 Del: integrated -- https://master.php.net/note/delete/75479/integrated Del: useless -- https://master.php.net/note/delete/75479/useless Del: bad code -- https://master.php.net/note/delete/75479/bad+code Del: spam -- https://master.php.net/note/delete/75479/spam Del: non-english -- https://master.php.net/note/delete/75479/non-english Del: in docs -- https://master.php.net/note/delete/75479/in+docs Del: other reasons-- https://master.php.net/note/delete/75479 Reject -- https://master.php.net/note/reject/75479 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127096) next »