How can I print Hindi sentences(unicode) on image in Python?

前端 未结 3 1260
醉话见心
醉话见心 2021-02-07 04:40

I have a file named \"hindi.txt\". It has contents as follows. I\'m using Python3.5.

कामकाजी महिलाओं के लिए देश में दिल्ली असुरक्षित, सिक्किम सबसे बेहतर: रिपोर्ट         


        
3条回答
  •  青春惊慌失措
    2021-02-07 05:13

    Pillow 7.0.0 provides support for rendering complex font with raqm library

    To check for support:

    >>> from PIL import features
    >>> print(features.check("raqm"))
    True
    

    If it returns False check if library is installed:

     /sbin/ldconfig -p | grep raqm
        libraqm.so.0 (libc6,x86-64) => /usr/lib/libraqm.so.0
        libraqm.so (libc6,x86-64) => /usr/lib/libraqm.so
    

    To Install raqm in debian based distros: sudo apt-get install libraqm-dev

    To use raqm as layout engine add layout_engine option while initializing font:

    font = ImageFont.truetype("foo.ttf", size=90, layout_engine=ImageFont.LAYOUT_RAQM)
    

    The above code is tested for: Hindi, Marathi, Gujrati and Telugu fonts.

提交回复
热议问题