Displaying from right to left connected languages ​​(such as Persian and Arabic) in GD - Possible PHP error

I want to create an image with text on it using php gd library.

everything is fine, but when I try to write a word from right to left (for example, Persian) using imagefttext(), my text renders from left to right (reverse) and the characters are no longer connected,

example of related characters: ماه example of unrelated characters: م ا ه

Here is my code:

    header('Content-Type: image/jpeg');
    $thumb_path = "...";
    $font_path = "..."
    $img = imagecreatefromjpeg($thumb_path);
    $color = "...";
    // __month is a Persian word :  ( م ا ه -->  ماه )
    $text = $months." ".__month;
    imagefttext($img,29, 10, 230, 135, $color, $font_path, $text); // <--
    imagejpeg($img);

Image displayed:

month

I know that my problem is not in coding. Because I already tried this:

$text = mb_convert_encoding($text, "HTML-ENTITIES", "UTF-8");

And the result is the same.

, . , , , gd ?

​​ gd?

+3
2

, ( ), PHP , , :

php-gd-farsi

:

enter image description here

PHP ( ). :

// init:
include('php-gd-farsi-master/FarsiGD.php');
$gd = new FarsiGD();

....
// then convert your text:
$tx = $gd->persianText($str, 'fa', 'normal');

!: -)

:

<?php

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, 0x00, 0x00);

// Make the background red
imagefilledrectangle($im, 0, 0, 299, 99, $red);

// Path to our ttf font file
//$font_file = './Vera.ttf';
$font_file = './cour.ttf';

// Draw the text 'PHP Manual' using font size 13
$text = imagecreatetruecolor(200, 60);
imagefilledrectangle($text, 0, 0, 200, 60, $red);
$str = '**ماه**';
$tx = $gd->persianText($str, 'fa', 'normal');
imagefttext($text, 24, 10, 10, 50, $black, $font_file,$tx );
$im = $text;

// Output image to the browser
header('Content-Type: image/png');

imagepng($im);
imagedestroy($im);
?>
+8

?

, , Farsi - fa_IR.UTF-8 fa_utf8. , :

$rv = setlocale(LC_ALL, "fa_IR.UTF-8");
var_dump($rv);

: , .

0

All Articles