如何更改 php gd 库中 imagefttext() 结果的编码?

发布于 2024-12-02 18:54:58 字数 442 浏览 1 评论 0原文

我正在尝试更改 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风追烟花雨 2024-12-09 18:54:58

阿拉伯字符不能被视为数组。另外,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

差↓一点笑了 2024-12-09 18:54:58

imagettftext 手册的注释中,有一个 RTL 语言的示例。 试试这个

    $wordsArray = explode(" ", $text);

    $rtlCompleteText='';
    for ($i = sizeOf($wordsArray); $i > -1; $i = $i-1) {

        //$lettersArray = explode("|", str_replace(";|", ";", $wordsArray[$i]));
        $lettersArray = explode(";", $wordsArray[$i]);

        $rtlWord='';
        for ($k = sizeOf($lettersArray); $k > -1; $k = $k-1) {
            if (strlen($lettersArray[$k]) > 1) { // make sure its full unicode letter
                $rtlWord = $rtlWord."".$lettersArray[$k].";";
            }
        }

        $rtlCompleteText = $rtlCompleteText." ".$rtlWord;

    }

    return $rtlCompleteText;
} 

in the comments of the manual for imagettftext, there's an example for RTL languages. Try this

    $wordsArray = explode(" ", $text);

    $rtlCompleteText='';
    for ($i = sizeOf($wordsArray); $i > -1; $i = $i-1) {

        //$lettersArray = explode("|", str_replace(";|", ";", $wordsArray[$i]));
        $lettersArray = explode(";", $wordsArray[$i]);

        $rtlWord='';
        for ($k = sizeOf($lettersArray); $k > -1; $k = $k-1) {
            if (strlen($lettersArray[$k]) > 1) { // make sure its full unicode letter
                $rtlWord = $rtlWord."".$lettersArray[$k].";";
            }
        }

        $rtlCompleteText = $rtlCompleteText." ".$rtlWord;

    }

    return $rtlCompleteText;
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文