I am writing a small program in python using PIL library to write a tamil text on the screen using tamil fonts. However, the certain letters in tamil font are not displayed properly. Some characters are not aesthetically printed on image like பி, ழ், த், து, யோ, கு, டி. Need to use any reshaper or any other thing in code. Could some one throw light on this issue?
Example: இனிய பிறந்தநாள் வாழ்த்துக்கள் யோஷினி குட்டி
Code:
import numpy as np
from PIL import ImageFont, ImageDraw, Image
import cv2
## Make canvas and set the color
img = np.zeros((720, 1280,3),np.uint8)
b,g,r,a = 0,0,0,255 #black
#fontpath = "C:/Ubuntusharefolder/CustomFonts/akshar.ttf" # <== தமிழ்
#fontpath = "C:/Ubuntusharefolder/CustomFonts/Coiny-Regular.ttf" # <== தமிழ்
#fontpath = "C:/Ubuntusharefolder/CustomFonts/NotoSansTamil-Regular.ttf" # <== தமிழ்
fontpath = "C:/Ubuntusharefolder/CustomFonts/latha/latha.ttf" # <== தமிழ்
print(">>>font path:", fontpath)
font = ImageFont.truetype(fontpath, 32)
line = "இனிய பிறந்தநாள் வாழ்த்துக்கள் யோஷினி குட்டி"
img_pil = Image.fromarray(img)
draw = ImageDraw.Draw(img_pil)
b,g,r,a = 255,255,255,0 #white
y_pos = 200
x_pos = 100
draw.text((x_pos, y_pos), line, font = font, fill = ((b, g, r, a)))
res_img = np.array(img_pil)
## Display
cv2.imshow("result", res_img);cv2.waitKey();cv2.destroyAllWindows()
#cv2.imwrite("result.png", res_img)
Try
font = ImageFont.truetype(fontpath, 32, layout_engine=ImageFont.LAYOUT_RAQM)
By default the layout engine might be basic. Tamil fonts use advanced true type features for rendering. LAYOUT_RAQM should do the trick