php – 将阿拉伯语写入图像时出错
发布时间:2020-12-13 16:40:35 所属栏目:PHP教程 来源:网络整理
导读:我以前的相关问题: php work with images : write complete word in arabic,ttf font 我的问题是: 如果我想在图像中写入????,它会显示为???? 嗯,我修好了,现在输出:???? 使用此功能: function arab($word){ $w = explode(' ',$word) ; $f = array(array(
我以前的相关问题:
php work with images : write complete word in arabic,ttf font 我的问题是: >如果我想在图像中写入????,它会显示为???? 使用此功能: function arab($word){ $w = explode(' ',$word) ; $f = array(array('?','?'),'?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?'); $t = array(array('?_','?_'),'?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_','?_'); $my_arab = '' ; foreach($w as $wo) { $r = array() ; $wo = str_replace($f,$t,$wo); $ne = explode('_',$wo) ; foreach($ne as $new) { $new = str_replace('_','',$new) ; array_unshift($r,$new); } $my_arab .= ' '.implode('',$r) ; } return trim($my_arab) ; } 但新问题是: ??? (分开的字母)应该是: ???? 如何解决这个问题?
你的倒转阿拉伯字符的方式没有考虑到连接字形的本质.
但是,解决PHP / GD不能自动支持RTL语言(如阿拉伯语)的问题是一个有效的手段. 您需要做的是使用完全符合您预期的ar-php库. 确保您的PHP文件编码是unicode / UTF. 使用imagettftext在PHP中使用阿拉伯语排版的示例: <?php // The text to draw require('./I18N/Arabic.php'); $Arabic = new I18N_Arabic('Glyphs'); $font = './DroidNaskh-Bold.ttf'; $text = $Arabic->utf8Glyphs('???? ??????'); // Create the image $im = imagecreatetruecolor(600,300); // Create some colors $white = imagecolorallocate($im,255,255); $grey = imagecolorallocate($im,128,128); $black = imagecolorallocate($im,0); imagefilledrectangle($im,599,299,$white); // Add the text imagettftext($im,50,90,$black,$font,$text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im,"./output_arabic_image.png"); echo 'open: ./output_arabic_image.png'; imagedestroy($im); ?> 输出: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |