如何在图像中写入阿拉伯语或波斯语等非英语字符?

Ehs*_*san 10 php gd

如何使用PHP GD库将阿拉伯语或波斯语字符写入图像?

即"احسان"

Hus*_*sni 0

尝试使用 imagettftext。

\n\n
<?php\n// http://localhost/test.php?text=\xd8\xa7\xd8\xad\xd8\xb3\xd8\xa7\xd9\x86\n\n// test.php file\n\n$font = 'C:/Windows/Fonts/Arial.ttf';\n$text = $_GET['text'];\n\n// [switch to right to left] \n// try comparing of using this block and not using this block\n$rtl = array();\nfor($i=0; $i<strlen($text); $i+=2) {\n    $rtl[] = substr($text, $i, 2);\n}\n$rtl = array_reverse($rtl);\n$rtl = implode($rtl);\n$text = $rtl;\n// [/switch to right to left]\n\n$im = imagecreatetruecolor(65, 35);\n$black = imagecolorallocate($im, 0, 0, 0);  \n$white = imagecolorallocate($im, 255, 255, 255);\nimagefilledrectangle($im, 0, 0, 500, 100, $white);  \nimagettftext($im, 12, 0, 10, 20, $black, $font, $text);  \nheader('Content-type: image/png');  \n\nimagepng($im);  \nimagedestroy($im); \n
Run Code Online (Sandbox Code Playgroud)\n

  • 它会打印 ¡ ¡ ¡ ä 而不是 ¡ (4认同)