2011-09-15 31 views

回答

0

嘗試使用imagettftext。

<?php 
// http://localhost/test.php?text=احسان 

// test.php file 

$font = 'C:/Windows/Fonts/Arial.ttf'; 
$text = $_GET['text']; 

// [switch to right to left] 
// try comparing of using this block and not using this block 
$rtl = array(); 
for($i=0; $i<strlen($text); $i+=2) { 
    $rtl[] = substr($text, $i, 2); 
} 
$rtl = array_reverse($rtl); 
$rtl = implode($rtl); 
$text = $rtl; 
// [/switch to right to left] 

$im = imagecreatetruecolor(65, 35); 
$black = imagecolorallocate($im, 0, 0, 0); 
$white = imagecolorallocate($im, 255, 255, 255); 
imagefilledrectangle($im, 0, 0, 500, 100, $white); 
imagettftext($im, 12, 0, 10, 20, $black, $font, $text); 
header('Content-type: image/png'); 

imagepng($im); 
imagedestroy($im); 
+3

它會打印احسانانسان – shampoo

1

使用此功能,以通過文本imagettftext

<?php 
function revUni($text) { 

    $wordsArray = explode(" ", $text); 

    $rtlCompleteText=''; 
    for ($i = sizeOf($wordsArray); $i > -1; $i = $i-1) { 

     //$lettersArray = explode("|", str_replace(";|", ";", $wordsArray[$i])); 
     $lettersArray = explode(";", $wordsArray[$i]); 

     $rtlWord=''; 
     for ($k = sizeOf($lettersArray); $k > -1; $k = $k-1) { 
      if (strlen($lettersArray[$k]) > 1) { // make sure its full unicode letter 
       $rtlWord = $rtlWord."".$lettersArray[$k].";"; 
      } 
     } 

     $rtlCompleteText = $rtlCompleteText." ".$rtlWord; 

    } 

    return $rtlCompleteText; 
} 
?> 
0

說白了倒車阿拉伯字符像數組是不會工作。您需要考慮阿拉伯字形並用確切的Unicode符號替換每個字形。在這裏看到一個類似的問題和解決方案:Error while writting Arabic to image

0

我寫了一個基於庫的作曲家包,我不記得名字。我修改了這個庫並修復了它的一些錯誤。

你可以找到來源here。你也可以通過運行與作曲家安裝:

composer require quince/persian-gd 
  • 它有波斯文字沒有問題
  • 這是定製
  • 字符串不會溢出的圖像畫布出

請測試它,併發送錯誤報告,建議和...

謝謝

相關問題