使用PHP将RTL(阿拉伯语)文本写入图像

使用PHP将RTL(阿拉伯语)文本写入图像,php,image,image-processing,Php,Image,Image Processing,我想生成一个带有一些文本的图像,LTR语言似乎运行良好,但当用阿拉伯语尝试时,它根本不起作用,请参见下面的屏幕截图,其中我用显示的文本代码绘制了3个文本字符串 下面是我的测试代码(带有一些注释): 最后,我在其他一些论坛上找到了一个解决方案,这是一个很小的库,工作非常完美,整个过程就是将阿拉伯字母转换为unicode符号,实际上,转换为: $text = 'العربية'; 为此: $text = 'ﺔﻴﺑ&#xF

我想生成一个带有一些文本的图像,LTR语言似乎运行良好,但当用阿拉伯语尝试时,它根本不起作用,请参见下面的屏幕截图,其中我用显示的文本代码绘制了3个文本字符串

下面是我的测试代码(带有一些注释):


最后,我在其他一些论坛上找到了一个解决方案,这是一个很小的库,工作非常完美,整个过程就是将阿拉伯字母转换为unicode符号,实际上,转换为:

$text = 'العربية'; 
为此:

$text = 'ﺔﻴﺑﺮﻌﻟﺍ';
使用该库进行转换,因此在我之前的代码中,它的工作方式是这样的(包括库之后):


()

您可以查看此库

下面是一个如何使用它的示例

require('../I18N/Arabic.php');  
$Arabic = new I18N_Arabic('Glyphs'); 
$text = 'بسم الله الرحمن الرحيم';  
$text = $Arabic->utf8Glyphs($text);

你已经试过我想的方法了?或也许你没有,也许你只是尝试了是的,你是对的,但我不认为这一个对我有帮助,但我会尝试一下,谢谢你的快速回答:)事实上,这个解决方案并不接近我的问题,你说的对吗?我说的是:我没有试过希伯来语,因为我只需要一个阿拉伯语的有效解决方案。word2uni的链接断开了。我需要它。请帮助。@hosein,通过电子邮件与我联系,我可以发送给你。我在stackoverflow中找不到你的电子邮件。请给我你的emailword2uni做得很好,但忽略了一些阿拉伯字符,如发音符号/Harakat/Tashkeel。要获得完全支持,请尝试ar-phpwork2uni-lib链接:
// Create a 300*300 image
$im = imagecreate(300, 300);

// Yellow transparent background and blue text
$bg = imagecolorallocatealpha($im, 255, 255, 0, 45);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write an LTR string
imagestring($im, 5, 250, 100, 'test', $textcolor);

$font = 'DroidKufi-Regular.ttf'; // specify the fonts file
$text = "تجربة";
$text = word2uni( $text );
// Add the text
imagettftext($im, 10, 0, 10, 20, $textcolor, $font, $text);


// set a red text color 
$textcolor = imagecolorallocate($im, 255, 0, 0);

// strrev doesn't seem to solve the problem
$text = strrev( $text );
// add the text
imagettftext($im, 10, 0, 30, 250, $textcolor, $font, $text);

imagefilledrectangle ($im, 0, 0, 1, 1, $bg);

// Output the image
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
require('../I18N/Arabic.php');  
$Arabic = new I18N_Arabic('Glyphs'); 
$text = 'بسم الله الرحمن الرحيم';  
$text = $Arabic->utf8Glyphs($text);