Skip to content

Commit edea1c8

Browse files
authored
Merge pull request #14 from tjacobs/fontfix
Fix the rendervideo missing font
2 parents 72d2a7a + e9ee681 commit edea1c8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

toddlerbot/locomotion/train_mjx.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,16 @@ def make_text_image(text: str, font_size: int = 18):
276276
"RGBA", (final_video.w, final_video.h), (0, 0, 0, 0)
277277
) # Transparent background
278278
draw = ImageDraw.Draw(img)
279-
font = ImageFont.truetype("DejaVuSans-Bold.ttf", font_size)
279+
try:
280+
# Try to load the preferred font
281+
font = ImageFont.truetype("DejaVuSans-Bold.ttf", font_size)
282+
except (OSError, IOError):
283+
try:
284+
# Fallback to system default font
285+
font = ImageFont.load_default()
286+
except (OSError, IOError):
287+
# Last resort: use default font
288+
font = None
280289
draw.text((10, 10), text, font=font, fill="white")
281290
return img
282291

0 commit comments

Comments
 (0)