added variable font
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
from typing import Iterable
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import os
|
||||
|
||||
datei_endung = ".png"
|
||||
|
||||
img = None
|
||||
output_img = None
|
||||
font = ImageFont.truetype("res/fonts/NotoSans-Regular.ttf", 12)
|
||||
_bkp_font = ImageFont.truetype("res/fonts/NotoSans-Regular.ttf", 12) #in case set_font does funky stuff, backup the original font
|
||||
font = _bkp_font
|
||||
|
||||
|
||||
def NSD_init(x: float, y: float):
|
||||
@@ -15,6 +17,16 @@ def NSD_init(x: float, y: float):
|
||||
img = Image.new("RGB", (x, y), "white")
|
||||
output_img = ImageDraw.Draw(img)
|
||||
|
||||
def set_font(font_filepath: str):
|
||||
if not os.path.exists(font_filepath):
|
||||
raise FileNotFoundError("")
|
||||
try:
|
||||
font = ImageFont.truetype(font_filepath)
|
||||
except:
|
||||
font = _bkp_font
|
||||
raise
|
||||
|
||||
|
||||
def get_text_size(text: str):
|
||||
if not font:
|
||||
raise Exception("Output image was not initialized! Make sure to call NSD_init first")
|
||||
|
||||
Reference in New Issue
Block a user