From 74f6d7aa403c397368ff29c24b97fafa03d0e20b Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sat, 15 Mar 2025 16:03:14 +0000 Subject: Initial commit --- imggen.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 imggen.py (limited to 'imggen.py') diff --git a/imggen.py b/imggen.py new file mode 100644 index 0000000..cdc6314 --- /dev/null +++ b/imggen.py @@ -0,0 +1,36 @@ +from PIL import Image, ImageDraw, ImageFont +import math +import printer + +font_bold = ImageFont.truetype("/usr/share/fonts/TTF/IosevkaSS08-Bold.ttc", 70, encoding="unic") +font_norm = ImageFont.truetype("/usr/share/fonts/TTF/IosevkaSS08-Regular.ttc", 40, encoding="unic") + +MAX_WIDTH = 576 + +def name(name: str): + txt_len = font_bold.getlength(name) + if txt_len > MAX_WIDTH: + img = Image.new('RGB', (math.ceil(txt_len), 80), (255, 255, 255)) + else: + img = Image.new('RGB', (MAX_WIDTH, 80), (255, 255, 255)) + + draw = ImageDraw.Draw(img) + draw.text((0, 0), name, font=font_bold, fill="black") + + if font_bold.getlength(name) > MAX_WIDTH: + wpercent = (MAX_WIDTH / float(img.size[0])) + hsize = int((float(img.size[1]) * float(wpercent))) + img = img.resize((MAX_WIDTH, hsize), Image.Resampling.LANCZOS) + + new_img = Image.new('RGB', (MAX_WIDTH, 80), (255, 255, 255)) + new_img.paste(img, (0,math.floor(80-hsize))) + img = new_img + + return img + +def pronouns(pronouns: str): + img = Image.new('RGB', (MAX_WIDTH, 50), (255, 255, 255)) + draw = ImageDraw.Draw(img) + draw.text((0, 0), pronouns, font=font_norm, fill="black") + return img + -- cgit v1.2.3-70-g09d2