Index: t3lib/class.t3lib_stdgraphic.php =================================================================== --- t3lib/class.t3lib_stdgraphic.php (revision 8471) +++ t3lib/class.t3lib_stdgraphic.php (working copy) @@ -1280,6 +1280,11 @@ $breakWidth = $conf['breakWidth']; $breakSpace = $this->getBreakSpace($conf); + //Bounding box is needed for total image width + if ($conf['align'] == 'right' || $conf['align'] == 'center') { + $boundingBox = $this->calcBBox($conf); + } + $wordPairs = $this->getWordPairsForLineBreak($string); // Iterate through all word pairs: foreach ($wordPairs as $index => $wordPair) { @@ -1288,8 +1293,10 @@ $currentWidth+= $wordWidth; $phrase.= $wordPair; } else { - // Render the current phrase that is below breakWidth: - $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF); + //Recalc width to skip trailing blanks + $currentWidth = $this->getRenderedTextWidth(trim($phrase), $conf); + // Render the current phrase that is below breakWidth - set x position depending on alignment: + $this->ImageTTFTextWrapper($im, $fontSize, $angle, ($conf['align'] == 'right' ? $boundingBox[0] - $currentWidth + $x : ($conf['align'] == 'center' ? ($boundingBox[0] - $currentWidth) / 2 + $x : $x)), $y, $color, $fontFile, trim($phrase), $splitRendering, $sF); // Calculate the news height offset: $y+= $breakSpace; // Restart the phrase: @@ -1299,7 +1306,7 @@ } // Render the remaining phrase: if ($currentWidth) { - $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $phrase, $splitRendering, $sF); + $this->ImageTTFTextWrapper($im, $fontSize, $angle, ($conf['align'] == 'right' ? $boundingBox[0] - $currentWidth + $x : ($conf['align'] == 'center' ? ($boundingBox[0] - $currentWidth) / 2 + $x : $x)), $y, $color, $fontFile, trim($phrase), $splitRendering, $sF); } } else { $this->ImageTTFTextWrapper($im, $fontSize, $angle, $x, $y, $color, $fontFile, $string, $splitRendering, $sF);