From 0a790e8a75ba9822c412bdc1af9a677d35ada0e4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 3 Oct 2024 21:11:48 +0200 Subject: [PATCH] vertical text generator into function --- main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index bea5c85..2d007fe 100644 --- a/main.py +++ b/main.py @@ -58,6 +58,17 @@ def get_sign_image(image: str): return enhanced_image +def vertical_text(text: str, font: ImageFont.ImageFont | ImageFont.FreeTypeFont): + """Image with vertical text""" + text_img = Image.new("RGBA", (135, 24), (255, 255, 255, 0)) + + text_draw = ImageDraw.Draw(text_img) + text_draw.text((0, 0), f"{text:^15}", font=font, fill="black") + text_draw = text_img.rotate(90, expand=True) + + return text_draw + + def create_horoscope_image(horoscope: dict[str, dict[str, str]]): """Generate horoscope images""" img_width, img_height = 1200, 425 @@ -75,10 +86,7 @@ def create_horoscope_image(horoscope: dict[str, dict[str, str]]): image.paste(sign_image, (x + 20, y), sign_image) # Sign text - text_img = Image.new("RGBA", (135, 24), (255, 255, 255, 0)) - text_draw = ImageDraw.Draw(text_img) - text_draw.text((0, 0), f"{sign:^15}", font=font_sign, fill="black") - text_draw = text_img.rotate(90, expand=True) + text_draw = vertical_text(sign, font_sign) image.paste(text_draw, (x - 10, y - 10), text_draw) # Love prediction