Skip to content

Commit d1a0a39

Browse files
Kut Akdoganclaude
andcommitted
Add label_date option, separator line, and improved label spacing
Add label_date boolean to group config for appending UTC timestamp. Draw black separator line between screenshot and label banner. Increase padding and line spacing in label for better readability. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5968285 commit d1a0a39

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

shots/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ShotGroup:
2828
shots: list[ShotSpec]
2929
output: str = "png" # "png" or "pdf"
3030
label: str | None = None # template string applied to all shots
31+
label_date: bool = False # add date/time line below the label
3132
folder: str | None = None # override subfolder name (defaults to id)
3233

3334

@@ -129,6 +130,7 @@ def load_config(path: str) -> RunConfig:
129130
shots=shots,
130131
output=output,
131132
label=str(g["label"]).strip() if g.get("label") else None,
133+
label_date=bool(g.get("label_date", False)),
132134
folder=str(g["folder"]).strip() if g.get("folder") else None,
133135
))
134136

shots/image_ops.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,40 @@ def _get_font(size: int) -> ImageFont.FreeTypeFont | ImageFont.ImageFont:
8686

8787
def add_label_banner(png_bytes: bytes, label_text: str, font_size: int = 32) -> bytes:
8888
"""
89-
Add a white banner with black text below the image. Additive — does not
90-
crop into the screenshot, just extends the canvas downward.
89+
Add a white banner with black text below the image, separated by a black
90+
line. Additive — does not crop into the screenshot, just extends the canvas
91+
downward. Supports multiline text (e.g. label + date on separate lines).
9192
"""
9293
im = Image.open(BytesIO(png_bytes)).convert("RGBA")
9394
w, h = im.size
9495

9596
font = _get_font(font_size)
96-
padding = font_size // 2
97-
banner_h = font_size + 2 * padding
97+
line_thickness = 2
98+
padding = font_size # gap above and below text block
99+
line_spacing = font_size // 2 # extra gap between lines
98100

99-
# New canvas: original + banner
101+
# Measure multiline text height
102+
tmp_draw = ImageDraw.Draw(im)
103+
text_bbox = tmp_draw.multiline_textbbox((0, 0), label_text, font=font, spacing=line_spacing)
104+
text_block_h = text_bbox[3] - text_bbox[1]
105+
106+
banner_h = line_thickness + 2 * padding + text_block_h
107+
108+
# New canvas: original + separator + banner
100109
out = Image.new("RGBA", (w, h + banner_h), (255, 255, 255, 255))
101110
out.paste(im, (0, 0))
102111

103112
draw = ImageDraw.Draw(out)
104-
bbox = draw.textbbox((0, 0), label_text, font=font)
105-
text_w = bbox[2] - bbox[0]
113+
114+
# Black separator line
115+
draw.rectangle([(0, h), (w, h + line_thickness)], fill=(0, 0, 0, 255))
116+
117+
# Centered multiline text
118+
text_bbox = draw.multiline_textbbox((0, 0), label_text, font=font, spacing=line_spacing)
119+
text_w = text_bbox[2] - text_bbox[0]
106120
text_x = (w - text_w) // 2
107-
text_y = h + padding
108-
draw.text((text_x, text_y), label_text, fill=(0, 0, 0, 255), font=font)
121+
text_y = h + line_thickness + padding
122+
draw.multiline_text((text_x, text_y), label_text, fill=(0, 0, 0, 255), font=font, align="center", spacing=line_spacing)
109123

110124
buf = BytesIO()
111125
out.save(buf, format="PNG")

shots/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,11 @@ def run_config(
470470
"id": shot.id,
471471
"title": shot.description.strip()[:80],
472472
})
473+
if group.label_date:
474+
from datetime import datetime, timezone
475+
label_text += "\n" + datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
473476
out_bytes = add_label_banner(out_bytes, label_text)
474-
log.info("added label: %s", label_text)
477+
log.info("added label: %s", label_text.replace("\n", " | "))
475478

476479
# Save individual shot PNG
477480
shot_png_path = group_dir / f"{safe_filename(shot.id)}.png"

0 commit comments

Comments
 (0)