From 1bcb39820c77f385796251922836fc49a9214384 Mon Sep 17 00:00:00 2001 From: jimmy Date: Thu, 21 Jul 2022 19:48:30 +1200 Subject: [PATCH] Dynamically generate --- printer/test.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/printer/test.py b/printer/test.py index 4561cde..7275d9f 100644 --- a/printer/test.py +++ b/printer/test.py @@ -1,15 +1,19 @@ import StarTSPImage from PIL import Image, ImageDraw, ImageFont, ImageOps import textwrap +import random -# with open("printer/locations.txt") as locations: -# pass +with open("printer/locations.txt") as locations: + lines = locations.read().splitlines() + location = random.choice(lines) -# with open("printer/actions.txt") as actions: -# pass +with open("printer/actions.txt") as actions: + lines = actions.read().splitlines() + action = random.choice(lines) -# with open("printer/adverb.txt") as adverb: -# pass +with open("printer/adverbs.txt") as adverb: + lines = adverb.read().splitlines() + adverb = random.choice(lines) im=Image.open("printer/image2.jpg") @@ -18,10 +22,11 @@ f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 40) txt=Image.new('L', (1000,230)) d = ImageDraw.Draw(txt) +text = "While {}, {}, {}".format(location, action, adverb) text_short = "By the DJ, offer a stranger a drink" text_long = "In the outdoor area, ask someone would you rather be known for always being honest or always being kind" -lines = textwrap.wrap(text_long, width=23) +lines = textwrap.wrap(text, width=23) if len(lines) > 2: im=Image.open("printer/image.jpg")