note 81829 added to function.imagestring

From: Date: Fri, 14 Mar 2008 22:10:47 +0000
Subject: note 81829 added to function.imagestring
Groups: php.notes 
Request: Send a blank email to php-notes+get-137075@lists.php.net to get a copy of this message
Creates a box of text. Has horizontal and vertical alignment, box arguments, and custom leading. I submitted this to the manual in 2003 actually, but it disappeared after a year or so (not sure why). Here it is again. <?php define("ALIGN_LEFT", "left"); define("ALIGN_CENTER", "center"); define("ALIGN_RIGHT", "right"); define("VALIGN_TOP", "top"); define("VALIGN_MIDDLE", "middle"); define("VALIGN_BOTTOM", "bottom"); function imagestringbox(&$image, $font, $left, $top, $right, $bottom, $align, $valign, $leading, $text, $color) { // Get size of box $height = $bottom - $top; $width = $right - $left; // Break the text into lines, and into an array $lines = wordwrap($text, floor($width / imagefontwidth($font)), "\n", true); $lines = explode("\n", $lines); // Other important numbers $line_height = imagefontheight($font) + $leading; $line_count = floor($height / $line_height); $line_count = ($line_count > count($lines)) ? (count($lines)) : ($line_count); // Loop through lines for ($i = 0; $i < $line_count; $i++) { // Vertical Align switch($valign) { case VALIGN_TOP: // Top $y = $top + ($i * $line_height); break; case VALIGN_MIDDLE: // Middle $y = $top + (($height - ($line_count * $line_height)) / 2) + ($i * $line_height); break; case VALIGN_BOTTOM: // Bottom $y = ($top + $height) - ($line_count * $line_height) + ($i * $line_height); break; default: return false; } // Horizontal Align $line_width = strlen($lines[$i]) * imagefontwidth($font); switch($align) { case ALIGN_LEFT: // Left $x = $left; break; case ALIGN_CENTER: // Center $x = $left + (($width - $line_width) / 2); break; case ALIGN_RIGHT: // Right $x = $left + ($width - $line_width); break; default: return false; } // Draw imagestring($image, $font, $x, $y, $lines[$i], $color); } return true; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 138.23.21.189 ---- Manual Page -- http://www.php.net/manual/en/function.imagestring.php Edit -- https://master.php.net/note/edit/81829 Del: integrated -- https://master.php.net/note/delete/81829/integrated Del: useless -- https://master.php.net/note/delete/81829/useless Del: bad code -- https://master.php.net/note/delete/81829/bad+code Del: spam -- https://master.php.net/note/delete/81829/spam Del: non-english -- https://master.php.net/note/delete/81829/non-english Del: in docs -- https://master.php.net/note/delete/81829/in+docs Del: other reasons-- https://master.php.net/note/delete/81829 Reject -- https://master.php.net/note/reject/81829 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137075) next »