5

Im using GraphicsMagick for node and 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.

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

Output Image:

enter image description here

If Im trying using reverse urdu "مكيلع مالسلا" string even then text isn't being drawn correctly.

enter image description here

What m i doing wrong? How can I fix it?

Thanks,

Aqib Mumtaz
  • 4,936
  • 1
  • 36
  • 33

2 Answers2

4

i'm searching for the same thing and i found that
you need to enable the text_shaping option
you need to configure FFmpeg with --enable-libfribidi
read about text_shaping here
https://ffmpeg.org/ffmpeg-filters.html#Syntax
i didn't test it but i will, when i get a result i will post the code here
i wish i have pointed you out here's a working code i use to produce videos like this enter image description here

ffmpeg -y -loop 1 -framerate 25 -i bachground-img.jpg -vf "drawtext=text_shaping=1:fontfile=C\/:/Windows/Fonts/tradbdo.ttf:\
textfile=text-new.txt:fontcolor=white:fontsize=75:x=(w-tw)/2:y=h-25*t:" -t 45 -pix_fmt yuv420p output.mp4
  • Thanks for your response. this is bit old question. it would be great if you could post a working code – Aqib Mumtaz Dec 25 '17 at 08:31
  • I'm using complied windows version and it's not support `libfribidi` do I have to recompile it on windows from source ! – Salem Apr 13 '18 at 17:27
0

I face exactly the same problem, and after days of searching I found a great npm library which fix this problem, the good thing with this library is that it works with both English & Arabic languages.

the library is : @mapbox/mapbox-gl-rtl-text.

https://www.npmjs.com/package/@mapbox/mapbox-gl-rtl-text

const rtlText = require('@mapbox/mapbox-gl-rtl-text');

var arabicString = "السلام عليكم";
var shapedArabicText = rtlText.applyArabicShaping(arabicString);
var readyForDisplay = rtlText.processBidirectionalText(shapedArabicText, []);
yaa200
  • 46
  • 3