Raouf Athar
Raouf Athar

Reputation: 1813

How to properly write unicode words to image using PHP imgttftext() function

I am trying to write some Urdu text on an image using imgttftext() function of PHP. It does not display the characters unless I convert the text using the following code:

function convert($text){
    $out="";
    mb_language('uni');
    mb_internal_encoding('UTF-8');
    $text = mb_convert_encoding($text, 'HTML-ENTITIES',"UTF-8");
    $text = html_entity_decode($text,ENT_NOQUOTES, "ISO-8859-1");
    for($i = 0; $i < strlen($text); $i++) {
        $letter = $text[$i];
        $num = ord($letter);
        if($num>127) {
              $out .= "&#$num;";
        } else {
              $out .=  $letter;
        }
    }
    return $out;
}

Now, the text e.g. عچں (which contains the three characters ع چ ں) is printed on to the image as separate and full characters instead of cutting and joining the characters to form an Urdu word like عچں.

I have used the characters ا ب ت ث with codes U+0627, U+0628, U+0629 and so on from this page http://en.wikipedia.org/wiki/List_of_Unicode_characters#Arabic

I have shared the code here: https://code.google.com/p/urdu-captcha/downloads/list

Note: I have added space between the characters in the code provided removing which makes no difference to how the text is displayed on the image.

How do I make it write the characters joined together to form proper words?

Upvotes: 3

Views: 2188

Answers (1)

herrjeh42
herrjeh42

Reputation: 2793

You'll need an additional library to perform Arabic glyph joining. Check out AR-PHP.

Upvotes: 4

Related Questions