note 101537 added to function.imagettfbbox
| From: | a2hansolo at gmail dot com | Date: | Thu, 23 Dec 2010 07:29:49 +0000 |
| Subject: | note 101537 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175156@lists.php.net to get a copy of this message | ||
//measure bg image size, wrap text to fit image width
$mx = imagesx($main_img);
$my = imagesy($main_img);
//TEXT VARS/////////
$main_text = ;
$main_text_size = ;
$main_text_x = ($mx/2);
$main_text_color = imagecolorallocate($main_img, $main_text_red, $main_text_green, $main_text_blue);
$words = explode(' ', $main_text);
$lines = array($words[0]);
$currentLine = 0;
for($i = 1; $i < count($words); $i++)
{
$lineSize = imagettfbbox($main_text_size, 0, $mt_f, $lines[$currentLine] . ' ' .
$words[$i]);
if($lineSize[2] - $lineSize[0] < $mx)
{
$lines[$currentLine] .= ' ' . $words[$i];
}
else
{
$currentLine++;
$lines[$currentLine] = $words[$i];
}
}
$line_count = 1;
// Loop through the lines and place them on the image
foreach ($lines as $line)
{
$line_box = imagettfbbox($main_text_size, 0, $mt_f, "$line");
$line_width = $line_box[0]+$line_box[2];
$line_height = $line_box[1]-$line_box[7];
$line_margin = ($mx-$line_width)/2;
$line_y = (($line_height+12) * $line_count);
imagettftext($main_img, $main_t_s, 0, $line_margin, $line_y, $main_text_color, $mt_f, $line);
// Increment Y so the next line is below the previous line
$line_count ++;
}
----
Server IP: 208.69.120.55
Probable Submitter: 75.99.14.243
----
Manual Page -- http://www.php.net/manual/en/function.imagettfbbox.php
Edit -- https://master.php.net/note/edit/101537
Del: integrated -- https://master.php.net/note/delete/101537/integrated
Del: useless -- https://master.php.net/note/delete/101537/useless
Del: bad code -- https://master.php.net/note/delete/101537/bad+code
Del: spam -- https://master.php.net/note/delete/101537/spam
Del: non-english -- https://master.php.net/note/delete/101537/non-english
Del: in docs -- https://master.php.net/note/delete/101537/in+docs
Del: other reasons-- https://master.php.net/note/delete/101537
Reject -- https://master.php.net/note/reject/101537
Search -- https://master.php.net/manage/user-notes.php