2010-09-13 27 views
2

我試圖用PHP編寫圖像中的阿拉伯文字。 這是我的代碼:如何在PHP中使用圖像編寫阿拉伯文字

<?php 

header("Content-Type: image/png; charset=utf8"); 
$im = imagecreatetruecolor(150, 30); 

// Create some colors 
$white = imagecolorallocate($im, 100, 255, 255); 
$grey = imagecolorallocate($im, 128, 128, 128); 
$black = imagecolorallocate($im, 0, 0, 0); 
imagefilledrectangle($im, 0, 0, 399, 29, $white); 

$font = 'tahoma.ttf'; 
$t = strrev('إن الدين عند الله الإسلام'); 
$text=utf8_encode($t); 
imagettftext($im, 20, 0, 10, 20, $black, $font, $text); 
imagepng($im); 
imagedestroy($im); 
?> 

謝謝。

+0

你可以使用這個鏈接 [看這裏] [1] [1]:HTTP://計算器.com/questions/1284896/export-arabic-text-as-images – 2015-08-22 23:15:18

回答

3

輸出是什麼?

strrev函數不是unicode兼容的 http://de2.php.net/manual/en/function.strrev.php 請參閱那裏的註釋以獲取與unicode兼容的示例。

也看到imagettftext頁, 我覺得這樣的評論正是你所需要的: http://de2.php.net/manual/en/function.imagettftext.php#97767

+0

輸出是文本但不是阿拉伯語。 – AboSami 2010-09-13 09:54:11

+0

使用您的原始代碼?您是否嘗試/閱讀我發佈的鏈接? – Kissaki 2010-09-17 09:57:41

+0

**對不起,但這不會工作**。該評論的鏈接將阿拉伯字符視爲一個數組。它假設只有一種形式的字符是有效的,而不是。阿拉伯字符根據單詞中的位置改變形狀,即字形。對於類似的問題和答案:[http://stackoverflow.com/questions/993265/writing-text-with-diacritic-nikud-vocalization-marks-using-pil-python-imag/25727238#25727238](http: //stackoverflow.com/questions/993265/writing-text-with-diacritic-nikud-vocalization-marks-using-pil-python-imag/25727238#25727238) – 2014-09-09 21:46:37

0

這會爲你工作:

  1. 包括( 「fagd.php」);
  2. use imagettftext($ im,20,0,10,20,$ black,$ font,fagd($ text));

fagd.php碼在這裏:

http://cdn.shirazitco.ir/fagd.txt

+0

驚人的解決方案..對我來說非常完美!但鏈接被打破,所以我添加了另一個鏈接:http://www.koders.com/php/fidBBD43C6EF0FFB00FED0AC734BC2EFB293A6CBBC3.aspx – Zorox 2012-07-26 11:31:12

+1

嗯,我試過這個,但它沒有工作...你能發佈你是如何做到的嗎?我仍然有亂碼(不是阿拉伯語)字符。 – user961627 2012-08-10 19:30:14

+0

鏈接不起作用。 – 2014-08-03 15:33:31