如何在PHP中将文本转换为图像时加入Urdu字母表

Zeh*_*oor 12 php urdu

我使用TIC将文本转换为图像.

我已经对此进行了大量搜索,但它似乎是Unicode问题(初始内侧和最终字母的unicodes)或者可能是内容类型,因为图像是在PNG中.

如果我没有呼应与图像转换content type text/htmlcharset=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);
Run Code Online (Sandbox Code Playgroud)

出去吧

? ? ? ?  ? ? ? 
Run Code Online (Sandbox Code Playgroud)

Pmp*_*mpr 4

你可以这样做:

\n\n
$text = "\xd8\xb2\xdb\x81\xd8\xb1\xdb\x81 \xd9\x86\xd9\x88\xd8\xb1";\n\n// Make it RTL\npreg_match_all(\'/([^\\d]|\\d+)/us\', $text, $ar);\n$text = join(\'\',array_reverse($ar[0]));\n\n// Set font\n$font = \'C:\\Windows\\Fonts\\Nastalique.ttf\';\n\n// Create the image\n$im = imagecreatetruecolor(160, 160);\n$white = imagecolorallocate($im, 255, 255, 255);\n$black = imagecolorallocate($im, 0, 0, 0);\n\n// Create some colors\nimagefilledrectangle($im, 0, 0, 159, 159, $white);\n\n// Set the headers\nheader(\'Content-type: image/gif\');\n\n// Add the text\nimagettftext($im, 12, 0, 20, 20, $black, $font, $text);\nimagegif($im);\nimagedestroy($im);\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果不适合您,您可以选择使用php-gd-farsi

\n\n

如何使用

\n\n

只需将库复制到您的 PHP 目录即可。用法很简单:

\n\n
include(\'php-gd-farsi-master/FarsiGD.php\');\n$gd = new FarsiGD();\n\n....\n// then convert your text:\n$tx = $gd->persianText($str, \'fa\', \'normal\');\n
Run Code Online (Sandbox Code Playgroud)\n\n

完整代码

\n\n
include(\'php-gd-farsi-master/FarsiGD.php\');\n\n$gd = new FarsiGD();\n\n// Create a 300x100 image\n$im = imagecreatetruecolor(300, 100);\n$red = imagecolorallocate($im, 0xFF, 0x00, 0x00);\n$black = imagecolorallocate($im, 0x00, 0x00, 0x00);\n\n// Make the background red\nimagefilledrectangle($im, 0, 0, 299, 99, $red);\n\n// Path to our ttf font file\n$font_file = \'./Nastalique.ttf\';\n\n// Draw the text \'PHP Manual\' using font size 13\n$text = imagecreatetruecolor(200, 60);\nimagefilledrectangle($text, 0, 0, 200, 60, $red);\n$str = \'\xd8\xb2\xdb\x81\xd8\xb1\xdb\x81 \xd9\x86\xd9\x88\xd8\xb1\';\n$tx = $gd->persianText($str, \'fa\', \'normal\');\nimagefttext($text, 24, 10, 10, 50, $black, $font_file,$tx );\n$im = $text;\n\n// Output image to the browser\nheader(\'Content-Type: image/png\');\n\nimagepng($im);\nimagedestroy($im);\n
Run Code Online (Sandbox Code Playgroud)\n