0

i'm using this code to write text on image but in Arabic and the problem is the letters are written from left to right. I use this code

header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = 'نص عربي';
$text = mb_convert_encoding($text, 'HTML-ENTITIES',"UTF-8");
$text = html_entity_decode($text,ENT_NOQUOTES, "ISO-8859-1");
$font =  'arial.ttf';
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);

The result is this image with letters written from left to right and unreadable so how to set the correct encoding to print Arabic text on the image

enter image description here

PHP User
  • 2,350
  • 6
  • 46
  • 87
  • does gd even support rtl languages? – Marc B Sep 18 '15 at 21:57
  • Do you need to write just one single word (or at most just one single line), as shown in the example image? If so, I’d say just try and revert the order of the letters, before passing it to imagettftext … – CBroe Sep 19 '15 at 17:57

0 Answers0