From 39c2fbc6bdd696fa88ff4aa53b95b2f5aa607b08 Mon Sep 17 00:00:00 2001 From: James Pattinson Date: Wed, 18 Feb 2026 05:18:25 -0500 Subject: [PATCH] New Notes template --- templates.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/templates.py b/templates.py index 9cf41da..7f99494 100644 --- a/templates.py +++ b/templates.py @@ -227,10 +227,74 @@ def new_label_large_template(variables, width_pixels=991, height_pixels=413, fil return image +def notes_1_template(variables, width_pixels=991, height_pixels=413, filename=None): + """Notes template with animal/date header and wrapped notes""" + image = Image.new('RGB', (width_pixels, height_pixels), 'white') + draw = ImageDraw.Draw(image) + + try: + font_header = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 36) + font_notes = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 32) + font_small = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 28) + except: + font_header = ImageFont.load_default() + font_notes = ImageFont.load_default() + font_small = ImageFont.load_default() + + margin = 10 + top = margin + left_col = margin + right_margin = margin + line_height = 46 + + animal = variables.get('animal', '') + note_date = variables.get('date', '') + notes = variables.get('notes', '') + + # Animal (left) and date (right) on the same line + draw.text((left_col, top), animal, fill='black', font=font_header) + bbox = draw.textbbox((0, 0), note_date, font=font_small) + date_width = bbox[2] - bbox[0] + draw.text((width_pixels - right_margin - date_width, top + 4), note_date, fill='black', font=font_small) + + # Wrapped notes below the header + notes_top = top + line_height + 10 + max_width = width_pixels - (left_col + right_margin) + + def wrap_text(text, font, max_px): + lines = [] + for raw_line in text.splitlines(): + words = raw_line.split() + if not words: + lines.append('') + continue + line = [] + for word in words: + test_line = ' '.join(line + [word]) + bbox = draw.textbbox((0, 0), test_line, font=font) + test_width = bbox[2] - bbox[0] + if test_width <= max_px or not line: + line.append(word) + else: + lines.append(' '.join(line)) + line = [word] + if line: + lines.append(' '.join(line)) + return lines + + for i, line in enumerate(wrap_text(notes, font_notes, max_width)): + draw.text((left_col, notes_top + i * (line_height - 6)), line, fill='black', font=font_notes) + + if filename: + image.save(filename) + + return image + # Template registry TEMPLATES = { 'vet_label': vet_label_template, 'new_label': new_label_template, 'new_label_large': new_label_large_template, + 'notes_1': notes_1_template, # Add more templates here, e.g., 'vet_label_small': vet_label_small_template } \ No newline at end of file