加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 14:02:11 所属栏目:PHP教程 来源:网络整理
导读:我使用 TIC将文本转换为图像. 我已经搜索了很多,但似乎是Unicode问题(初始中间和最后的字母的unicodes),或者可能是像PNG中的内容类型. 如果我没有使用内容类型为text / html和charset = UTF-8的图像转换进行回显,我将使用加入Urdu字母获得所需的输出. requir
我使用 TIC将文本转换为图像.

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

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

require_once 'lib/tic.php';
$text="???? ??? ";

TIC::factory('C:WindowsFontsNastalique.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:WindowsFontsNastalique.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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读