From 3c4b27623d58f8781438285db4a65762f3435c21 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 May 2026 21:24:18 +0000 Subject: [PATCH 1/2] Initial plan From 4236e6e1cdb1fc0de6ce8686a29242c46ab2ade5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 1 May 2026 21:26:45 +0000 Subject: [PATCH 2/2] Fix exif text overlap with color palette in border Agent-Logs-Url: https://github.com/Rustymage/photoborder/sessions/78577cd4-f8d6-4fef-8e79-0cc07f5257cd Co-authored-by: Rustymage <19926955+Rustymage@users.noreply.github.com> --- border.py | 22 ++++++++++++++++++++-- main.py | 17 +++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/border.py b/border.py index f1cf37f..309cb40 100644 --- a/border.py +++ b/border.py @@ -4,7 +4,7 @@ import math from enum import Enum from dataclasses import dataclass -from PIL import Image +from PIL import Image, ImageFont, ImageDraw import text as tm class BorderType(Enum): @@ -123,11 +123,29 @@ def draw_border(img: Image, border: Border) -> Image: return canvas -def draw_exif(img: Image, exif: dict, border: Border, fontpath: str, boldfontpath: str) -> Image: +def draw_exif(img: Image, exif: dict, border: Border, fontpath: str, boldfontpath: str, max_width: int = None) -> Image: centered = border.border_type in (BorderType.POLAROID, BorderType.LARGE, BorderType.INSTAGRAM) multiplier = 0.2 if centered else 0.5 font_size = tm.get_optimal_font_size("Test string", border.bottom * multiplier, fontpath) heading_font_size = tm.get_optimal_font_size("Test string", border.bottom * (multiplier + 0.02), boldfontpath) + + if max_width and not centered: + exif_lines = [ + f"{exif['Make']} {exif['Model']}", + f"{exif['LensMake']} {exif['LensModel']}", + f"{exif['FocalLength']} {exif['FNumber']} {exif['ISOSpeedRatings']} {exif['ExposureTime']}", + ] + dummy = ImageDraw.Draw(img) + while font_size > 1: + test_heading = ImageFont.truetype(boldfontpath, heading_font_size) + test_font = ImageFont.truetype(fontpath, font_size) + widths = [dummy.textlength(exif_lines[0], font=test_heading)] + \ + [dummy.textlength(line, font=test_font) for line in exif_lines[1:]] + if max(widths) <= max_width: + break + font_size -= 1 + heading_font_size = max(1, heading_font_size - 1) + font = tm.create_font(font_size, fontpath) heading_font = tm.create_font(heading_font_size, boldfontpath) diff --git a/main.py b/main.py index 9149cab..e37751b 100644 --- a/main.py +++ b/main.py @@ -75,6 +75,16 @@ def process_image(path: str, add_exif: bool, add_palette: bool, border_type: Bor img_with_border = draw_border(img, border) save_as = f'{filename}_border-{border.border_type}' + exif_max_width = None + + if add_palette: + palette_size = round(border.bottom / 3) + color_palette = load_image_color_palette(img, palette_size) + # Position palette on right side of bottom border + palette_x = img_with_border.width - border.right - color_palette.width + palette_y = img_with_border.height - round(border.bottom / 2) - round(color_palette.height / 2) + exif_max_width = palette_x - border.left + if add_exif: exif = get_exif(img) if exif: @@ -89,15 +99,10 @@ def process_image(path: str, add_exif: bool, add_palette: bool, border_type: Bor if len(error_messages) > 0: raise ValueError(error_messages) - img_with_border = draw_exif(img_with_border, exif, border, font_path, bold_font_path) + img_with_border = draw_exif(img_with_border, exif, border, font_path, bold_font_path, max_width=exif_max_width) save_as = f'{save_as}_exif' if add_palette: - palette_size = round(border.bottom / 3) - color_palette = load_image_color_palette(img, palette_size) - # Position palette on right side of bottom border - palette_x = img_with_border.width - border.right - color_palette.width - palette_y = img_with_border.height - round(border.bottom / 2) - round(color_palette.height / 2) img_with_border = overlay_palette(img=img_with_border, color_palette=color_palette, offset=(palette_x, palette_y))