50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import string
|
|
import pathlib
|
|
from PIL import ImageFont
|
|
|
|
BASE64_DIGITS = string.digits + string.ascii_letters + "+_"
|
|
|
|
FONT_SIZE = 120
|
|
FONT_COLOR = (0,0,0)
|
|
IMAGE_BACKGROUND = (255,255,255)
|
|
IMAGE_SIZE = (1800, 1200)
|
|
|
|
MARGINS = 60
|
|
|
|
|
|
def base64(num: int) -> str:
|
|
temp = ""
|
|
while num > 0:
|
|
temp = BASE64_DIGITS[num % 64] + temp
|
|
num = num//64
|
|
|
|
return temp
|
|
|
|
|
|
def make_fonts():
|
|
with open("font-list.txt", "r", encoding="utf-8") as file_pointer:
|
|
fonts = file_pointer.read().split("\n")
|
|
|
|
image_fonts = {}
|
|
for font_name in fonts:
|
|
if font_name[0] == "#":
|
|
continue
|
|
font_name = font_name.replace(" ","-")
|
|
if pathlib.Path(f"./fonts/{font_name}.TTF").is_file():
|
|
file_type = "TTF"
|
|
elif pathlib.Path(f"./fonts/{font_name}.OTF").is_file():
|
|
file_type = "OTF"
|
|
else:
|
|
print(f"Could not locate font \033[0;31m{font_name}\033[0m")
|
|
continue
|
|
|
|
font_path = f"./fonts/{font_name}.{file_type}"
|
|
new_font = ImageFont.truetype(font_path, FONT_SIZE)
|
|
image_fonts[font_name] = new_font
|
|
print(f"Successfully loaded font \033[0;32m{font_name}\033[0m")
|
|
|
|
return image_fonts
|
|
|
|
|
|
FONTS = make_fonts()
|