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; }
/** * Remove blank columns and blank rows from the image edge * Then resize the image based on this area to the given size * * @param image $image * @param int $x The width * @param int $y The height * * @return image a copy of the image of size x,y only containing the bounding box * @author Adam Zammit <*****@*****.**> * @since 2010-10-14 */ function resize_bounding(&$image, $x = 44, $y = 34) { $new = imagecreate($x, $y); list($tlx, $tly, $brx, $bry) = bounding_box($image); $width = $brx - $tlx; $height = $bry - $tly; if ($width < 1) { $width = 1; } if ($height < 1) { $height = 1; } // Find the centre $xc = $width / 2 + $tlx; $yc = $height / 2 + $tly; // Preserve aspect ratio to an extent if ($width < $height) { $aspect = $width / $height; $aspect2 = pow($aspect, 1 / 3); $height2 = $height; $width2 = $height * $aspect2; $dx = ($width2 - $width) / 2; // Resize $blank = imagecreate($width2, $height2); imagecopy($blank, $image, $dx, 0, $tlx, $tly, $width, $height); imagecopyresized($new, $blank, 0, 0, 0, 0, $x, $y, $width2, $height2); } else { $aspect = $height / $width; $aspect2 = pow($aspect, 1 / 3); $width2 = $width; $height2 = $width * $aspect2; $dy = ($height2 - $height) / 2; // Resize $blank = imagecreate($width2, $height2); imagecopy($blank, $image, 0, $dy, $tlx, $tly, $width, $height); imagecopyresized($new, $blank, 0, 0, 0, 0, $x, $y, $width2, $height2); } return $new; }
gd_alpha(); imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), gd_bkg()); render_text($bounds); } break; case 'progressive': $bounds = bounding_box($FLIR['text']); if ($FStyle['realFontHeight'] != 'true') { $REAL_HEIGHT_BOUNDS = $bounds; } $offset_left = 0; $nsize = $FLIR['size_pts']; while (($REAL_HEIGHT_BOUNDS['height'] > $FLIR['maxheight'] || $bounds['width'] > $FLIR['maxwidth']) && $nsize > 2) { $nsize -= 0.5; $bounds = bounding_box($FLIR['text'], NULL, $nsize); $REAL_HEIGHT_BOUNDS = $FStyle['realFontHeight'] == 'true' ? bounding_box(HBOUNDS_TEXT, NULL, $nsize) : $bounds; } $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);
GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Facelift Image Replacement. If not, see <http://www.gnu.org/licenses/>. */ $PLUGIN_ERROR = false; define('FULL_CACHE_PATH', fix_path(getcwd() . '/' . $FLIR['cache'])); define('CONVERT', IM_EXEC_PATH . 'convert'); if (DEBUG && file_exists(FULL_CACHE_PATH)) { unlink(FULL_CACHE_PATH); } $image = false; if ($FLIR['text'][0] == '@') { $FLIR['text'] = '\\' . $FLIR['text']; } $bounds = bounding_box($FLIR['text']); // convertBoundingBox(imagettfbbox($FLIR['size_pts'], 0, $FLIR['font'], $FLIR['text'])); $fulltrim = ''; if ($FStyle['fixBaseline'] != 'true') { $bounds['height'] += 200; $REAL_HEIGHT_BOUNDS = $bounds; $fulltrim = '-trim +repage'; } $fore_hex = dec2hex($FLIR['color']['red'], $FLIR['color']['green'], $FLIR['color']['blue']); $bkg_hex = $FLIR['output'] == 'png' ? 'transparent' : '"#' . dec2hex($FLIR['bkgcolor']['red'], $FLIR['bkgcolor']['green'], $FLIR['bkgcolor']['blue']) . '"'; $opacity = ''; if ($FLIR['opacity'] < 100 && $FLIR['opacity'] >= 0) { $opacity = strlen($FLIR['opacity']) == 1 ? '0' . $FLIR['opacity'] : (strlen($FLIR['opacity']) > 2 ? substr($FLIR['opacity'], 0, 2) : $FLIR['opacity']); } switch ($FStyle['cAlign']) { case 'center':
/** * Remove blank columns and blank rows from the image edge * Then resize the image based on this area to the given size * * @param image $image * @param int $x The width * @param int $y The height * * @return image a copy of the image of size x,y only containing the bounding box * @author Adam Zammit <*****@*****.**> * @since 2010-10-14 */ function resize_bounding(&$image, $x = 44, $y = 34) { $new = imagecreate($x, $y); list($tlx, $tly, $brx, $bry) = bounding_box($image); $width = $brx - $tlx; $height = $bry - $tly; if ($width < 1) { $width = 1; } if ($height < 1) { $height = 1; } // Resize imagecopyresized($new, $image, 0, 0, $tlx, $tly, $x, $y, $width, $height); return $new; }
if (false !== $image) { // if cannot wrap, don't break and continue on to next mode break; } } case 'progressive': $bounds = bounding_box($FLIR['text']); if ($FStyle['fixBaseline'] != 'true') { $REAL_HEIGHT_BOUNDS = $bounds; } $offset_left = 0; $nsize = $FLIR['size_pts']; while (($REAL_HEIGHT_BOUNDS['height'] > $FLIR['maxheight'] || $bounds['width'] > $FLIR['maxwidth']) && $nsize > 2) { $nsize -= 0.5; $bounds = bounding_box($FLIR['text'], NULL, $nsize); $REAL_HEIGHT_BOUNDS = $FStyle['fixBaseline'] == 'true' ? bounding_box(HBOUNDS_TEXT, NULL, $nsize) : $bounds; } $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']); break; case 'spacer': if (false === @($image = imagecreatetruecolor($SPACE_BOUNDS['width'] * $SPACES_COUNT, 1))) { err('COULD_NOT_CREATE'); } imagesavealpha($image, true); imagealphablending($image, false);