在PHP中将文本转换为图像时,如何加入乌尔都语字母

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

我已经搜索了很多,但似乎是Unicode问题(初始中间和最后的字母的unicodes),或者可能是像PNG中的内容类型.

如果我没有使用内容类型为text / html和charset = UTF-8的图像转换进行回显,我将使用加入Urdu字母获得所需的输出.

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);
$black = imagecolorallocate($im,0);

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

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

// Add the text
imagettftext($im,12,20,$black,$font,$text);
imagegif($im);
imagedestroy($im);

如果没有为您工作,您可以选择使用php-gd-farsi.

如何使用

只需将库复制到您的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);

// Make the background red
imagefilledrectangle($im,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,200,60,$red);
$str = 'زہرہ نور';
$tx = $gd->persianText($str,'normal');
imagefttext($text,24,10,50,$font_file,$tx );
$im = $text;

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

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...