I want to display urdu text on image using python

334 Views Asked by At
from PIL import Image, ImageFont, ImageDraw

from matplotlib import pyplot as plt
import numpy as np
import cv2

text_string = u'تصوير'

img = Image.new('RGB', (200, 150))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('C:\\Windows\\Nafees Nastaleeq Urdu Font\\Nafees Nastaleeq(Updated).ttf', 50)

draw.text((25,40), text_string, fill='white', font=font)

img.show()

I want to show text on image but only urdu alphabets shown on image.

I want urdu ligature shown on image but in output only urdu alphabets shown on image.

1

There are 1 best solutions below

0
Andj On

Pillow requires Raqm for rendering complex script text. Raqm requires additional software, instructions for installing dependencies and building Raqm are available at https://github.com/HOST-Oman/libraqm.

For Windows look at https://github.com/python-pillow/Pillow/issues/4859 and Installing Raqm (Libraqm) Windows 10

A minimal example, using Raqm:

from PIL import Image, ImageFont, ImageDraw
text = 'اردو'
img = Image.new('RGB', (200, 150))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('~/Library/Fonts/Nafees Nastaleeq.ttf', 50, layout_engine=ImageFont.Layout.RAQM)
draw.text((25,40), text, fill='white', font=font)
img.show()