bunkahle / PILasOPENCV

Wrapper for Image functions which are called like in the PIL module but work internally with OpenCV

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is the size param in PILasOPENCV.ImageFont.truetype(font_path, size)?

xuehuachunsheng opened this issue · comments

According to the description, the size is in points. It is the same as that is Pillow ImageFont.
However in actually, they are not the same. listed as follows.

import PILasOPENCV as ImageFont
text = "This is a randomly text"
font = ImageFont.truetype("./fonts/汉仪细行楷简.ttf", 180)
size = ImageFont.getsize(text, font)
print(size)
# (5500, 369, 69)
import PIL.ImageFont as ImageFont
text = "This is a randomly text"
font = ImageFont.truetype("./fonts/汉仪细行楷简.ttf", 180)
size = font.getsize(text)
print(size)
# (1649, 165)

What is the mean in the 3rd channel in the result value? And is there any transform formula between the PIL.ImageFont size and PILasOPENCV.ImageFont size?

No, they are not the same in points. PILasOPENCV depends on the freetype module for the ttf fonts which has different sizes. At the moment there is no transform formula for the sizes. The third value of size is the baseline of the font, the former two mean width and height.

Okey... Thank you, I will try the freetype.