Tuesday, 29 January 2019

GD Library imagettftext getting problem in Gujarati Language Text

I have used GD Library to create "Text on Image". I am facing one issue that passing some Gujarati text but getting wrong output as below:

I am passing શુભરાત્રી and getting:

enter image description here

My code is:

        $textBox = imagettfbbox($fontSize, $angle, $font, $txt);

        $textWidth = abs(max($textBox[2], $textBox[5]));

        $textHeight = abs(max($textBox[5], $textBox[7]));

        $x = (imagesx($this->img) - $textWidth)/2;

        $y = ((imagesy($this->img) + $textHeight)/$h)-($lines-2)*$textHeight;

        $lines = $lines-1;

        // Added this line from SO answer.
        $txt = mb_convert_encoding($txt, "HTML-ENTITIES", "UTF-8");
        $txt = preg_replace('~^(&([a-zA-Z0-9]);)~', htmlentities('${1}'), $txt);

        //add some shadow to the text
        imagettftext($this->img, $fontSize, $angle, $x + 2, $y + 1, $white, $font, $txt);

        //add the text
        imagettftext($this->img, $fontSize, $angle, $x, $y, $maroon, $font, $txt);

I have already tried this answer in above code but didn't worked.

Can anyone help me please?



from GD Library imagettftext getting problem in Gujarati Language Text

No comments:

Post a Comment