gm icon indicating copy to clipboard operation
gm copied to clipboard

Unicode drawText "Right to Left" Language issue

Open aqibmumtaz opened this issue 11 years ago • 14 comments

Hi Team,

Im trying to drawText on image for "Urdu/Arabic Language" this text "السلام عليكم", text is being drawn on output image but it is being drawn "Left to Right" while it must be "Right to Left" as Arabic/Urdu are "Right to Left" languages. What m i doing wrong? How can I fix it?

                                                gm("/file.png")
                                                    .fill('#FF0066')
                                                    .drawText(100, -150, "السلام عليكم", 'Center')
                                                    .font("/alvi_Nastaleeq.ttf")
                                                    .fontSize('38px')
                                                    .encoding('Unicode')

Output Image: screen shot 2015-07-31 at 11 35 37 pm

http://stackoverflow.com/questions/31753132/unicode-drawtext-right-to-left-language-issue-in-graphicsmagick-for-node

Thanks,

aqibmumtaz avatar Jul 31 '15 18:07 aqibmumtaz

Any suggestion or pointer plz?

aqibmumtaz avatar Aug 03 '15 05:08 aqibmumtaz

What about reversing your text first?

"السلام عليكم".split('').reverse().join('')

drochag avatar Aug 25 '15 02:08 drochag

I tried reversing and showing, but still dont work. check out this question I updated it for revering text http://stackoverflow.com/questions/31753132/unicode-drawtext-right-to-left-language-issue-in-graphicsmagick-for-node

aqibmumtaz avatar Aug 25 '15 12:08 aqibmumtaz

what does flop do?

Aqib

On Tue, Aug 25, 2015 at 7:44 AM, Dan Rocha [email protected] wrote:

What about using flop? Give a look at the example https://github.com/aheckmann/gm/blob/master/examples/flop.js

— Reply to this email directly or view it on GitHub https://github.com/aheckmann/gm/issues/427#issuecomment-134456966.

aqibmumtaz avatar Aug 25 '15 12:08 aqibmumtaz

Flop mirrors the image horizontally, and not sure what you're trying to achieve, can you create an image with the expected result? With reversing the text the 2nd image in your stackoverflow question should be done

drochag avatar Aug 25 '15 13:08 drochag

as mentioned in question I m trying to print this text "السلام عليكم" and output result should be same text "السلام عليكم", but output text isn't being printed like that, all I need to achieve is printing Arabic/Urdu text.

How can I do that?

aqibmumtaz avatar Aug 26 '15 03:08 aqibmumtaz

Which is the output when reversing the text? Isn't the desired either?

drochag avatar Aug 26 '15 04:08 drochag

No, output isn't desired even after reversing, this is reverse text "مكيلع مالسلا" of "السلام عليكم", If I try using reversed text it isn't producing required results as shown in stackoverflow question.

aqibmumtaz avatar Aug 26 '15 04:08 aqibmumtaz

Maybe your problem would be easier to understand if you could provide a desired image, not sure if my browser encoding interferes but I see the reversed text pretty similar to the image you are receiving

drochag avatar Aug 26 '15 05:08 drochag

My INPUT text is "السلام عليكم" Matching Image:screen shot 2015-08-26 at 10 34 46 am and Required OUTPUT text must be same as is "السلام عليكم" Matching Image:screen shot 2015-08-26 at 10 34 58 am

Now Issue is output text doesn't matching with input text at all, Current Output text is:1

2ndly, If I tried reversing INPUT text as you suggested and used Reversed INPUT text "مكيلع مالسلا" Matching Image:screen shot 2015-08-26 at 10 34 52 am Still output text is appearing wrong as:2

so it doesn't matter if I use reversed string or not, my output results are not desired.

is that helps?

aqibmumtaz avatar Aug 26 '15 06:08 aqibmumtaz

@DanMMX is this question clear to you now?

aqibmumtaz avatar Aug 27 '15 04:08 aqibmumtaz

oh ok, now that you put those images (for everything) is much clearer, I thought it was a matter of font type, now I see it's not. Sorry I don't think I know how to help you, if you come up with a solution let us know

drochag avatar Aug 27 '15 05:08 drochag

I think its gm support team who can come up with solution, you need to fix the way gm is handling Arabic encoding, fonts and printing.

aqibmumtaz avatar Aug 27 '15 07:08 aqibmumtaz

It's old issue , but I was looking for a solution and I found this module https://github.com/louy/Javascript-Arabic-Reshaper

var ArabicReshaper = require('arabic-reshaper'); var txt = ArabicReshaper.convertArabic('العربية').split("").reverse().join(""); then you can print it correctly with .drawText(60, 500,txt)

hope someone find this useful .

m7md10 avatar Feb 25 '17 14:02 m7md10