Я пытаюсь прочитать файл ttf и нарисовать их на изображении.
Для некоторого файла ttf это работает, но я не знаю почему, В какой-то момент в моем цикле я получил ошибку.
Вот мой код:
Font_Dir="./Data/Font/"
#list of our letter
letter = 'A'.split() # 0 1 2 3 4 5 6 7 8 9 T O A L
u=0 #counter
for l in letter :
#define axes to position the letter
Xaxe, Yaxe, LetterSize =(70,5,150)
# select our background
# read in file
for f in tqdm(os.listdir(Font_Dir)):
path = os.path.join(Font_Dir,f)
if os.path.lexists(path) :
# read only ttf file
if f is not None and f.split('.')[-1] =="ttf":
image = Image.open('./Data/Back/blakgr.jpg')
# initialise the drawing context with
# the image object as background
draw = ImageDraw.Draw(image)
# create font object with the font file and specify
# desired size
font = ImageFont.truetype('./Data/Font/'+f, size=LetterSize, encoding="unic")
# starting position of the message
(x, y) = (Xaxe, Yaxe)
color = 'rgb(255, 255, 255)' # white color
draw.text((x, y), l, fill=color, font=font)
print(f)
Вот моя ошибка:
RoundedMplus1c-Light.ttf
RoundedMplus1c-Medium.ttf
RoundedMplus1c-Regular.ttf
RoundedMplus1c-Thin.ttf
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-8-10b258b35f40> in <module>()
34 (x, y) = (Xaxe, Yaxe)
35 color = 'rgb(255, 255, 255)' # white color
---> 36 draw.text((x, y), l, fill=color, font=font)
37
38
OSError: stack overflow