簡體   English   中英

Python PIL imagedraw 泰米爾語字體未以美觀的方式顯示

[英]Python PIL imagedraw tamil font not displayed in a aesthetically proper manner

我正在使用 PIL 庫在 python 中編寫一個小程序,以使用泰米爾語 fonts 在屏幕上寫入泰米爾語文本。 但是,泰米爾語字體中的某些字母無法正確顯示。 某些字符在圖像上並不美觀,例如 பி、ழ்、த்、து、யோ、கு、டி。 需要在代碼中使用任何重塑器或任何其他東西。 有人可以闡明這個問題嗎?

示例:இனிய பிறந்தநாள் வாழ்த்துக்கள்

顯示為: 泰米爾語文本打印不正確

理想顯示: 泰米爾語文本打印正確

代碼:

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)

嘗試

font = ImageFont.truetype(fontpath, 32, layout_engine=ImageFont.LAYOUT_RAQM)

默認情況下,布局引擎可能是基本的。 Tamil fonts 使用高級真實類型功能進行渲染。 LAYOUT_RAQM 應該可以解決問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM