File size: 1,536 Bytes
6eff894
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from PIL import Image, ImageDraw, ImageFont
import os

RESULTS = "results"
IMG1 = os.path.join(RESULTS, "temps.png")
IMG2 = os.path.join(RESULTS, "precip.png")
OUT  = os.path.join(RESULTS, "cover.png")
ASSETS_DIR = "assets"
ASSET_OUT = os.path.join(ASSETS_DIR, "cover.png")

def fail(msg):
    print(f"❌ {msg}")
    raise SystemExit(1)

if not os.path.exists(IMG1):
    fail(f"Missing {IMG1}. Run `make viz` first.")
if not os.path.exists(IMG2):
    fail(f"Missing {IMG2}. Run `make viz` first.")

img1 = Image.open(IMG1).convert("RGB")
img2 = Image.open(IMG2).convert("RGB")

w = min(img1.width, img2.width)
def resize_to_width(im, target_w):
    new_h = int(im.height * target_w / im.width)
    return im.resize((target_w, new_h))

img1 = resize_to_width(img1, w)
img2 = resize_to_width(img2, w)

pad = 16
title_h = 48
H = img1.height + img2.height + title_h + pad * 4
W = w + pad * 2

canvas = Image.new("RGB", (W, H), "white")

y = pad
canvas.paste(img1, (pad, y)); y += img1.height + pad
canvas.paste(img2, (pad, y)); y += img2.height + pad

draw = ImageDraw.Draw(canvas)
title = "Weather Data Fetcher — Automated Pipeline"
try:
    font = ImageFont.load_default()
except Exception:
    font = None

tw, th = draw.textbbox((0,0), title, font=font)[2:]
tx = (W - tw) // 2
ty = y
draw.text((tx, ty), title, fill="black", font=font)

os.makedirs(RESULTS, exist_ok=True)
canvas.save(OUT, optimize=True)
if ASSETS_DIR:
    os.makedirs(ASSETS_DIR, exist_ok=True)
    canvas.save(ASSET_OUT, optimize=True)
print(f"✅ Created {OUT}")