12

私の以前の関連する質問:

PHPは画像を扱います:アラビア語、ttfフォントで完全な単語を書きます

私の問題は:

  • احمد画像に書き込みたい場合は、次のように表示されますد م ح ا
  • さて、私はそれを修正し、今出力:ا ح م د

この関数の使用:

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) ;

}

しかし、新しい問題は次のとおりです。

ا ح م د

(区切り文字) あるべき場所:

احمد

どうすればこれを修正できますか?

4

3 に答える 3

9

アラビア文字を逆にするあなたの方法は、接続されたグリフの性質を考慮していません。ただし、 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); 
?>

出力:

ここに画像の説明を入力

于 2014-09-09T21:16:32.097 に答える
4

あなたはbidiコンバーターを使用する必要があります。画像にペルシア語を書き込むために使用します

<?php
#----------------------------------------------------------------------
# Persian Image 1
#----------------------------------------------------------------------
# Copyright (c) 2011 Saeed Arab Sheybani
#----------------------------------------------------------------------
# This program is under the terms of the GENERAL PUBLIC LICENSE (GPL)
# as published by the FREE SOFTWARE FOUNDATION. The GPL is available
# through the world-wide-web at http://www.gnu.org/copyleft/gpl.html
#----------------------------------------------------------------------
# Authors: Saeed Arab Sheybani <webrefer@Gmail.com>
# Thanks to TCPDF project @ http://www.tecnick.com/ i use unicode_data.php and bidi.php from this site
#----------------------------------------------------------------------

/**
 * A function to change persian or arabic text from its logical condition to visual
 *
 * @author      Saeed Arab Sheybani <webrefer@Gmail.com>
 * @param       string  Main text you want to change it
 * @param       boolean Apply e'raab characters or not? default is true
 * @param       boolean Which encoding? default it "utf8"
 * @param       boolean Do you want to change special characters like "allah" or "lam+alef" or "lam+hamza", default is true
 */
function Persian_image(&$str)
{
    include_once('bidi.php');

    $text = explode("\n", $str);

    $str = array();

    foreach($text as $line){
        $chars = bidi::utf8Bidi(bidi::UTF8StringToArray($line), 'R');
        $line = '';
        foreach($chars as $char){
            $line .= bidi::unichr($char);
        }

        $str[] = $line;
    }

    $str = implode("\n", $str);
}
于 2011-10-24T06:27:08.913 に答える
2

私はこれを問題なく使用しました: https://github.com/omid/Persian-Log2Vis

更新: Persian-Log2Vis をフォークし、一部のコードを変更して正常に動作するようにしました。 https://github.com/tahmasebi/Persian-Log2Vis

于 2014-09-02T09:38:19.663 に答える