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

前端 未结 3 1256
醉话见心
醉话见心 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 04:59

    Installing Raqm, is the ultimate clean soon,check following steps

    One of the following methods can be used for building Raqm:

    1. Raqm depends on the following libraries:

    FreeType HarfBuzz FriBiDi

    To install dependencies on Fedora:

    sudo dnf install freetype-devel harfbuzz-devel fribidi-devel gtk-doc

    To install dependencies on Ubuntu:

    sudo apt-get install libfreetype6-dev libharfbuzz-dev libfribidi-dev \ gtk-doc-tools

    On Mac OS X you can use Homebrew:

    `export XML_CATALOG_FILES="/usr/local/etc/xml/catalog" # for the docs`
    

    Once you have the source code and the dependencies, you can proceed to build. To do that, run the customary sequence of commands in the source code directory:

    To do that, run the customary sequence of commands in the source code directory (configure file is not found in the package, The key was to run autogen.sh before):

    $ ./autogen.sh
    $ ./configure
    $ make
    $ make install
    

    To run the tests:

    $ make check
    
    sudo ldconfig This step was needed!
    

    Run the following test script: (Make sure the fonts are installed sudo apt install fonts-indic)

    
    from PIL import Image, ImageFont, ImageDraw
    
    im = Image.new("RGB",(160, 160))
    draw = ImageDraw.Draw(im)
    
    font_telugu = ImageFont.truetype("/usr/share/fonts/truetype/fonts-telu-extra/Pothana2000.ttf",50)
    text_telugu = "నిత్య"
    
    font_hindi = ImageFont.truetype("/usr/share/fonts/truetype/Gargi/Gargi.ttf",50)
    text_hindi = "नित्य"
    
    draw.text((10, 10), text_telugu, font=font_telugu)
    draw.text((10, 90), text_hindi, font=font_hindi)
    im.show()
    
    
    1. install tar file from releases If you downloaded the release tarball, you shouldn’t run ./autogen.sh at all, just run steps ./configure directly.

    2. for ubuntu >=18.04, you can install package directly- The requirements for libraqm are:

    libc6   >= 2.14
    libfreetype6    >= 2.4.2
    libfribidi0 >= 1.0.0
    libharfbuzz0b   >= 2.1.1
    

    Install the raqm package Update the package index:

        sudo apt-get update
    

    Install libraqm0 deb package:

    sudo apt-get install libraqm0
    

    You can test your installation by:

    from PIL import features
    print(features.check("raqm"))
    # you should get True now
    

提交回复
热议问题