2017-10-11 143 views
0

我需要在RTL模式下寫入imagettftext,'因爲阿拉伯語是這樣的:我不是故意還原這些字母,我的意思是一個類似於css的RTL(方向:rtl),所以align-flag on正確的......我怎麼能?imagettftext和阿拉伯語言:我如何在RTL模式下書寫?

我的易代碼:

require('static/I18N/Arabic.php'); 
$Arabic = new I18N_Arabic('Glyphs'); 
$font="static/ArabicModern-Light.ttf"; 
$testo=$Arabic->utf8Glyphs($testo); 
imagettftext($im, 26, 0, 560, 345, $textcolor, $font, "\"".$testo."\""); 

謝謝!

enter image description here

回答

-1

最終尋找和下載Ar-PHP 4.0我已經更新了這個答案,用阿拉伯數字後。由於我不懂阿拉伯語,我使用Arabic Wikipedia page中的文字'العربية'。

來源:

<?php 

require_once('./Arabic.php'); 

$iw = 300; // image width. 
$ih = 150; // image height. 

$size = 40; 
$angle = 0; 
$font = 'arial'; 
$text = 'العَرَبِيَّة'; 

$obj = new I18N_Arabic('Glyphs'); 
$text = $obj->utf8Glyphs($text); 

$box = imagettfbbox($size, $angle, $font, $text); 
$tw = abs($box[6] - $box[4]); // text width. 
$th = abs($box[7] - $box[1]); // text height. 

$im = imagecreatetruecolor($iw, $ih); 
imagefill($im, 0, 0, 0x00c0c0c0); // set a grey background. 

// left aligned. 
imagettftext($im, $size, $angle, 0, $th, 0x00000000, $font, $text); 

// centre aligned. 
imagettftext($im, $size, $angle, ($iw/2) - ($tw/2), $th * 2, 0x00000000, $font, $text); 

// right aligned. 
imagettftext($im, $size, $angle, $iw - $tw, $th * 3, 0x00000000, $font, $text); 

header('Content-Type: image/png'); 
imagepng($im); 
imagedestroy($im); 

結果(用PHP 7.1生成):從維基百科

enter image description here

參考圖像:

enter image description here


編輯:下面是從text you linked到第一五行你comment比較,通過我上面(很明顯,一些小的改動來處理多行)寫的代碼運行:

您的原始圖像(裁剪)在左側,我生成的圖像在右側。

enter image description hereenter image description here

從沒有對準

除了正確這是一個比賽。

+0

不,這不是我的問題的答案:這是整個文本的定位,而不是一個RTL CSS樣......你知道,阿拉伯文寫的是右旗 – Zak

+0

我已經添加了一張什麼圖片我需要 – Zak

+0

@Zak你的問題不清楚。你明確地聲明「我的意思是一個類似於css的RTL,所以右對齊標誌」。對齊文本是我在這裏展示的。感謝您編輯您的問題以顯示您想要的結果,現在請編輯它以顯示您當前遇到的問題。 – timclutton

相關問題