function imagettftextbox($size_pts, $angle, $left, $top, $color, $font, $raw_text, $max_width, $align = 'left', $lineheight = 1.0) { global $FLIR; if ($lineheight < -1) { // will cause text to disappear off canvas $lineheight = 1.0; } $raw_textlines = explode("\n", $raw_text); $formatted_lines = $formatted_widths = array(); $max_values = bounding_box(HBOUNDS_TEXT); $previous_bounds = array('width' => 0); $longest_line = 0; $spaces = ' ' . str_repeat(' ', defined('SPACING_GAP') ? SPACING_GAP : 0); foreach ($raw_textlines as $text) { $bounds = bounding_box($text); if ($bounds['height'] > $max_lineheight) { $max_lineheight = $bounds['height']; } if ($bounds['belowBasepoint'] > $max_baseheight) { $max_baseheight = $bounds['belowBasepoint']; } if ($bounds['xOffset'] > $max_leftoffset) { $max_leftoffset = $bounds['xOffset']; } if ($bounds['yOffset'] > $max_rightoffset) { $max_rightoffset = $bounds['yOffset']; } if ($bounds['width'] < $max_width) { // text doesn't require wrapping $formatted_lines[] = $text; $formatted_widths[$text] = $longest_line = $bounds['width']; } else { // text requires wrapping $words = explode($spaces, trim($text)); $wordcnt = count($words); $test_line = ''; for ($i = 0; $i < count($words); $i++) { // test words one-by-one to see if they put the width over $prepend = $i == 0 ? '' : $test_line . $spaces; // add space if not the first word $working_line = $prepend . $words[$i]; $bounds = bounding_box($working_line); if ($bounds['width'] > $max_width) { // if working line is too big previous line isn't, use that if ($wordcnt == 1) { // cannot wrap a single word that is longer than bounding box return false; } $formatted_lines[] = $test_line; $formatted_widths[$test_line] = $previous_bounds['width']; $test_line = $words[$i]; $bounds = bounding_box($test_line); } else { // keep adding $test_line = $working_line; } if ($bounds['width'] > $longest_line) { $longest_line = $bounds['width']; } $previous_bounds = $bounds; } if ($test_line != '') { // if words are finished and there is something left in the buffer add it $bounds = bounding_box($test_line); $formatted_lines[] = $test_line; $formatted_widths[$test_line] = $bounds['width']; } } } $longest_line += abs($max_leftoffset); $max_lineheight = $max_values['height'] * $lineheight; if ($lineheight < 0) { $max_lineheight += $max_values['height']; } $image = imagecreatetruecolor($FStyle['notrim'] == 'true' ? $max_width : $longest_line, $max_lineheight * (count($formatted_lines) - 1) + $max_values['yOffset'] + $max_values['belowBasepoint']); gd_alpha($image); imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), gd_bkg($image)); for ($i = 0; $i < count($formatted_lines); $i++) { if ($i == 0) { $offset_top = $max_values['yOffset']; } else { $offset_top = $max_lineheight * $i + $max_values['yOffset']; } switch (strtolower($align)) { default: case 'left': $offset_left = 0; break; case 'center': $offset_left = ($max_width - $formatted_widths[$formatted_lines[$i]]) / 2; break; case 'right': $offset_left = $max_width - $formatted_widths[$formatted_lines[$i]] - 1; break; } imagettftext($image, $size_pts, $angle, $offset_left, $offset_top, gd_color($image), $font, $formatted_lines[$i]); $bounds = array('xOffset' => $offset_left, 'yOffset' => $offset_top); // render_text($bounds, $formatted_lines[$i], $image, $bounds); } return $image; }
$FLIR['size_pts'] = $nsize; if (false === @($image = imagecreatetruecolor($bounds['width'], $REAL_HEIGHT_BOUNDS['height']))) { err('COULD_NOT_CREATE'); } gd_alpha(); imagefilledrectangle($image, $offset_left, 0, imagesx($image), imagesy($image), gd_bkg()); imagettftext($image, $FLIR['size_pts'], 0, $bounds['xOffset'], $REAL_HEIGHT_BOUNDS['yOffset'], gd_color(), $FLIR['font'], $FLIR['text']); render_text($bounds); break; case 'spacer': if (false === @($image = imagecreatetruecolor($SPACE_BOUNDS['width'] * $SPACES_COUNT, 1))) { err('COULD_NOT_CREATE'); } imagesavealpha($image, true); imagealphablending($image, false); imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), gd_bkg()); break; } if ($FLIR['postscript']) { imagepsfreefont($FLIR['ps']['font']); } if (false !== $image) { switch ($FLIR['output']) { default: case 'png': imagepng($image, $FLIR['cache']); break; case 'gif': imagegif($image, $FLIR['cache']); break; case 'jpg':