gpt4 book ai didi

php - 将阿拉伯语写入图像时出错

转载 作者:可可西里 更新时间:2023-10-31 22:12:33 24 4
gpt4 key购买 nike

我之前的相关问题:

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。例如> 打开记事本 > 另存为 > 编码为 UTF-8

使用 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, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 599, 299, $white);

// Add the text
imagettftext($im, 50, 0, 90, 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);
?>

输出:

enter image description here

关于php - 将阿拉伯语写入图像时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7780339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com