summaryrefslogtreecommitdiffstats
path: root/imggen.py
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2025-03-15 16:03:14 +0000
committerLeonardo Bishop <me@leonardobishop.com>2025-03-15 16:03:14 +0000
commit74f6d7aa403c397368ff29c24b97fafa03d0e20b (patch)
tree9811a6e3225d18cce491c1f2300dee981faf7fe5 /imggen.py
Initial commit
Diffstat (limited to 'imggen.py')
-rw-r--r--imggen.py36
1 files changed, 36 insertions, 0 deletions
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
+