如何在PHP中将文本转换为图像时连接乌尔都语字母表

如何在PHP中将文本转换为图像时连接乌尔都语字母表,php,urdu,Php,Urdu,我使用它将文本转换为图像 我在这方面搜索了很多,但它看起来像是Unicode问题(首字母中间字母和最后字母的Unicode),或者可能是内容类型,因为图像是PNG格式的 如果我使用content-type text/html和charset=UTF-8在没有图像转换的情况下进行回显,我将使用连接乌尔都语字母获得所需的输出 require_once 'lib/tic.php'; $text="زہرہ نور "; TIC::factory('C:\Windows\Fonts\Nastaliqu

我使用它将文本转换为图像

我在这方面搜索了很多,但它看起来像是Unicode问题(首字母中间字母和最后字母的Unicode),或者可能是内容类型,因为图像是PNG格式的

如果我使用
content-type text/html
charset=UTF-8
在没有图像转换的情况下进行回显,我将使用连接乌尔都语字母获得所需的输出

require_once 'lib/tic.php';
$text="زہرہ نور ";

TIC::factory('C:\Windows\Fonts\Nastalique.ttf')
->setText($text)
->setPadding(10)
->setBgColor('ff0000')
->setFontColor(0xff, 0xff, 0x00)
->setFontSize(24)->create(true);
出狱

ز ہ ر ہ  ن و ر 

你可以这样做:

$text = "زہرہ نور";

// Make it RTL
preg_match_all('/([^\d]|\d+)/us', $text, $ar);
$text = join('',array_reverse($ar[0]));

// Set font
$font = 'C:\Windows\Fonts\Nastalique.ttf';

// Create the image
$im = imagecreatetruecolor(160, 160);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// Create some colors
imagefilledrectangle($im, 0, 0, 159, 159, $white);

// Set the headers
header('Content-type: image/gif');

// Add the text
imagettftext($im, 12, 0, 20, 20, $black, $font, $text);
imagegif($im);
imagedestroy($im);
如果不适用于您,您可以选择使用

如何使用

include('php-gd-farsi-master/FarsiGD.php');

$gd = new FarsiGD();

// Create a 300x100 image
$im = imagecreatetruecolor(300, 100);
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

// Make the background red
imagefilledrectangle($im, 0, 0, 299, 99, $red);

// Path to our ttf font file
$font_file = './Nastalique.ttf';

// Draw the text 'PHP Manual' using font size 13
$text = imagecreatetruecolor(200, 60);
imagefilledrectangle($text, 0, 0, 200, 60, $red);
$str = 'زہرہ نور';
$tx = $gd->persianText($str, 'fa', 'normal');
imagefttext($text, 24, 10, 10, 50, $black, $font_file,$tx );
$im = $text;

// Output image to the browser
header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);
只需将库复制到PHP目录。用法很简单:

include('php-gd-farsi-master/FarsiGD.php');
$gd = new FarsiGD();

....
// then convert your text:
$tx = $gd->persianText($str, 'fa', 'normal');
完整代码

include('php-gd-farsi-master/FarsiGD.php');

$gd = new FarsiGD();

// Create a 300x100 image
$im = imagecreatetruecolor(300, 100);
$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

// Make the background red
imagefilledrectangle($im, 0, 0, 299, 99, $red);

// Path to our ttf font file
$font_file = './Nastalique.ttf';

// Draw the text 'PHP Manual' using font size 13
$text = imagecreatetruecolor(200, 60);
imagefilledrectangle($text, 0, 0, 200, 60, $red);
$str = 'زہرہ نور';
$tx = $gd->persianText($str, 'fa', 'normal');
imagefttext($text, 24, 10, 10, 50, $black, $font_file,$tx );
$im = $text;

// Output image to the browser
header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);

萨拉:你能找到这个问题的答案吗?如果您有任何解决方案,请与他人分享。@Aqueel请随时检查答案。Trix无法解决此问题。你能用这段代码分享你的输出吗?