如何更改 php gd 库中 imagefttext() 结果的编码?
我正在尝试更改 imagefttext() 结果的编码。
我的想法是将一些“阿拉伯”语言的文本打印到指定的图像上,但结果显示很奇怪 表格。
我使用了这段代码,但它仅适用于英文字符串:
mb_internal_encoding('UTF-8');
$im =imagecreatefromjpeg('x.jpg');
$textcolor=imagecolorallocate($im, 0, 0, 255);
imagefttext($im, 18, 0, 10, 20,$textcolor,"Fonts/tahoma.ttf","mûםր ٣٠ٲف");
imagejpeg($im,"mozil.jpg",100);
imagedestroy($im);
我可以解决这个问题吗?
谢谢
I'm trying to change the encoding of my imagefttext() result.
My idea is to print some text in "Arabic" language onto a specified image , but the result appear in strange
form.
I used this code, but it is work correctly just with English string :
mb_internal_encoding('UTF-8');
$im =imagecreatefromjpeg('x.jpg');
$textcolor=imagecolorallocate($im, 0, 0, 255);
imagefttext($im, 18, 0, 10, 20,$textcolor,"Fonts/tahoma.ttf","مسعود أوزبل");
imagejpeg($im,"mozil.jpg",100);
imagedestroy($im);
Can i have any solution for this problem ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阿拉伯字符不能被视为数组。另外,
imagefttext()
不支持开箱即用的 RTL 语言,例如阿拉伯语。您需要做的是反转每个字符而不改变其形状(字形/符号)。 @Lars 答案不起作用,因为阿拉伯语中的字符可能会根据其在单词中的位置而改变。请参阅此处以获取类似的答案和解决方案:将阿拉伯语写入图像时出错Arabic characters can not be treated as an array. Also
imagefttext()
does not support RTL languages like Arabic out of the box. What you need to do is to reverse every character without changing its shape (glyph/symbol). @Lars answer won't work because a char in Arabic might change based on its position in the word. See here for a similar answer and a solution: Error while writting Arabic to image在 imagettftext 手册的注释中,有一个 RTL 语言的示例。 试试这个
in the comments of the manual for imagettftext, there's an example for RTL languages. Try this