2013-03-14 207 views
2

我用一些文本創建圖像,當旋轉爲0時,它很好,但是當rotation is > 0圖像看起來不好時,由於文本對齊,因爲默認對齊是左的。因爲每個值是動態的,所以我們無法修復它,請幫助我。imagettftext函數中文本的右對齊

$message = 'Thanks, Deep, for making time to have a coffee today Purushottam'; 
$no_of_characters_line = $temp_data['no_of_characters_line']; 
$lines = explode('|', wordwrap($message, $no_of_characters_line, '|')); 
// Starting Y position and X position 
$y = $temp_data['position_from_top']; 
$x = $temp_data['position_from_left']; 
$font_size = $temp_data['font_size']; 
$rotation_angle = $temp_data['rotation']; 
$line_height = $temp_data['line_height']; 

foreach ($lines as $line) 
    { 
    imagettftext($im, $font_size,$rotation_angle, $x, $y, $black, $font, $line); 
    // Increment Y so the next line is below the previous line 
    $y += $line_height; 
    } 

我也附加示例模板。 enter image description here

+0

你能舉一個例子說明文本如何渲染不合要求嗎? – FoolishSeth 2013-03-14 06:36:03

+1

您需要調整$ x和$ y。 $ x =水平像素,$ y =垂直像素 – ripa 2013-03-14 06:36:23

回答

0

您可以使用imagettfbbox來計算字符串大小(以像素爲單位)。然後,使用寬度,您將能夠計算將文本對齊到右側所需的偏移量。另外,請查閱imagettftext文檔以獲取文本對齊的一些示例。