from PIL import Image
from pathlib import Path
import base64, io, html, os
def load_frame(name):
return Image.open(f"/mnt/data/{name}.png").convert("RGB")
def crop_photo(frame_name, x, y, w=440, h=555):
im = load_frame(frame_name)
crop = im.crop((x, y, x+w, y+h))
crop.thumbnail((600, 760))
buf = io.BytesIO()
crop.save(buf, format="JPEG", quality=88)
return "data:image/jpeg;base64," + base64.b64encode(buf.getvalue()).decode()
def pil_data(im):
buf=io.BytesIO()
im.thumbnail((700,900))
im.save(buf,format="JPEG",quality=90)
return "data:image/jpeg;base64,"+base64.b64encode(buf.getvalue()).decode()
prodi_img = Image.open("/mnt/data/shared_image.webp").convert("RGB")
photo_sources = {
1: crop_photo("f2", 62, 360), 2: crop_photo("f2", 580, 360),
3: crop_photo("x2_5", 62, 600), 4: crop_photo("x2_5", 580, 600),
5: crop_photo("f3", 62, 750), 6: crop_photo("f3", 580, 750),
7: crop_photo("f4", 62, 420), 8: crop_photo("f4", 580, 420),
9: crop_photo("f5", 62, 365), 10: crop_photo("f5", 580, 365),
11: crop_photo("f6", 62, 285), 12: crop_photo("f6", 580, 285),
13: crop_photo("f7", 62, 900), 14: crop_photo("f7", 580, 900),
15: crop_photo("f9", 62, 190), 16: crop_photo("f9", 580, 190),
17: crop_photo("f10", 62, 700), 18: crop_photo("f10", 580, 700),
21: crop_photo("f12", 62, 900), 22: crop_photo("f12", 580, 900),
24: crop_photo("f13", 580, 900), 25: crop_photo("frame14", 62, 350),
}
photo_sources[19] = "https://upload.wikimedia.org/wikipedia/commons/b/bf/Gordonbrowndavos2008.jpg"
photo_sources[20] = "https://upload.wikimedia.org/wikipedia/commons/a/a8/Angela_Merkel_2019_%28cropped%29.jpg"
photo_sources[23] = "https://upload.wikimedia.org/wikipedia/commons/a/a6/Nicolas_Sarkozy_in_2010.jpg"
photo_sources[26] = pil_data(prodi_img)
cards = [
(1,"George W. Bush","United States","COMBATANT","US-led Operation Enduring Freedom, counterterrorism and combat operations alongside ISAF.","Requested portrait: 14 January 2003."),
(2,"Stephen Harper","Canada","COMBATANT","Kandahar combat operations, counter-insurgency and reconstruction support.","Requested portrait: 2006 library photograph; brown-haired appearance."),
(3,"Helen Clark","New Zealand","MID-COMBATANT","Bamyan Provincial Reconstruction Team, security patrols and Afghan development support.",""),
(4,"John Howard","Australia","COMBATANT","Special operations, counterterrorism and Australian deployment in Uruzgan.","Requested portrait: Peter Morris photograph with flag background and smile."),
(5,"Abdullah II","Jordan","MID-COMBATANT","Medical and humanitarian military assistance, including the Jordanian field hospital.",""),
(6,"Branko Crvenkovski","North Macedonia","MID-COMBATANT","ISAF military participation, security and force-protection duties.",""),
(7,"Sali Berisha","Albania","MID-COMBATANT","ISAF security contingent and military cooperation.",""),
(8,"Stjepan Mesić","Croatia","MID-COMBATANT","ISAF military participation and security support.",""),
(9,"Traian Băsescu","Romania","COMBATANT","Infantry deployments, security operations and operational support.",""),
(10,"Ferenc Gyurcsány","Hungary","MID-COMBATANT","Provincial reconstruction, security and ISAF responsibilities.",""),
(11,"Václav Klaus","Czech Republic","MID-COMBATANT","ISAF military assistance, medical and specialist support.",""),
(12,"Lech Kaczyński","Poland","COMBATANT","Polish military deployment, security operations and combat-capable forces.",""),
(13,"Valdas Adamkus","Lithuania","MID-COMBATANT","Chaghcharan Provincial Reconstruction Team and regional security.",""),
(14,"Aigars Kalvītis","Latvia","MID-COMBATANT","ISAF personnel and military support responsibilities.",""),
(15,"Toomas Hendrik Ilves","Estonia","COMBATANT","Forces operating in Helmand alongside British-led operations.",""),
(16,"Fredrik Reinfeldt","Sweden","MID-COMBATANT","Northern Afghanistan security, reconstruction and Provincial Reconstruction Team activities.",""),
(17,"Jens Stoltenberg","Norway","COMBATANT","Northern Afghanistan operations, military security and special-operations contributions.",""),
(18,"Anders Fogh Rasmussen","Denmark","COMBATANT","Helmand combat operations and British-led coalition cooperation.",""),
(19,"Gordon Brown","United Kingdom","COMBATANT","Helmand combat operations, counter-insurgency and coalition military support.","Requested photograph: World Economic Forum, Davos, 25 January 2008."),
(20,"Angela Merkel","Germany","MID-COMBATANT","Northern Afghanistan, Kunduz Provincial Reconstruction Team, reconstruction and security.","Requested portrait reference: 2019 red-jacket photograph."),
(21,"Jan Peter Balkenende","Netherlands","COMBATANT","Uruzgan deployment, operational security and counter-insurgency.","Requested portrait: 2006 portrait."),
(22,"Guy Verhofstadt","Belgium","MID-COMBATANT","Kabul security and Belgian air-force support.",""),
(23,"Nicolas Sarkozy","France","COMBATANT","French forces, operational security and counter-insurgency.","Requested photograph: EPP Summit, 28 October 2010; leaning back and looking sideways."),
(24,"José Luis Rodríguez Zapatero","Spain","MID-COMBATANT","Herat and Badghis regional security, reconstruction and Provincial Reconstruction Team responsibilities.",""),
(25,"José Sócrates","Portugal","MID-COMBATANT","ISAF military support, security and operational assistance.",""),
(26,"Romano Prodi","Italy","MID-COMBATANT","Western Afghanistan, Herat regional responsibilities, security and reconstruction.","Exact user-supplied photograph: UN flag, orange-brown background, dark suit and bright red striped tie.")
]
card_html=[]
for num,name,country,status,desc,note in cards:
cls="combat" if status=="COMBATANT" else "mid"
source_note=f'<p class="requested">{html.escape(note)}</p>' if note else ''
card_html.append(f"""
<article class="card">
<img class="portrait" src="{photo_sources[num]}" alt="{html.escape(name)} portrait">
<div class="identity"><span class="number">{num:02d}.</span> {html.escape(name)}</div>
<div class="country">{html.escape(country)}</div>
<div class="status {cls}">{status}</div>
<p class="description">{html.escape(desc)}</p>
{source_note}
</article>""")
page=f"""<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>World Leaders & Afghanistan Deployments — 21 August 2007</title>
<style>
:root{{--bg:#050505;--panel:#090909;--edge:#292929;--white:#f7f4ef;--muted:#b9b4ad;--scarlet:#8B0000;--yellow:#FFF2A6;--ink:#211b08}}
*{{box-sizing:border-box}} body{{margin:0;background:var(--bg);color:var(--white);font-family:Georgia,serif;padding:26px 18px 40px}}
header,.grid,.foot{{max-width:1180px;margin:0 auto}} h1{{font-size:clamp(26px,4vw,42px);margin:0 0 8px}}
.kicker{{color:var(--muted);font:600 12px/1.5 Arial,sans-serif;letter-spacing:1.4px;text-transform:uppercase}}
.intro{{color:#d2cec7;max-width:850px;line-height:1.6;margin:12px 0 20px;font-size:15px}}
.legend{{display:flex;gap:10px;flex-wrap:wrap;margin:0 0 22px}}
.status{{display:inline-block;border-radius:999px;padding:10px 15px;font:bold 13px/1.1 Arial,sans-serif;letter-spacing:.45px}}
.combat{{background:#8B0000;color:#fff}} .mid{{background:#FFF2A6;color:#211b08}}
.grid{{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px}}
.card{{background:var(--panel);border:1.5px solid var(--edge);border-radius:22px;padding:15px;overflow:hidden;display:flex;flex-direction:column;min-width:0}}
.portrait{{width:100%;height:340px;object-fit:contain;background:#111;border-radius:15px;display:block}}
.identity{{font-size:clamp(18px,2vw,23px);font-weight:700;line-height:1.25;margin:14px 0 5px}}
.number{{color:#d8d2ca}} .country{{font:600 12px/1.4 Arial,sans-serif;color:var(--muted);letter-spacing:1.4px;margin:0 0 13px;text-transform:uppercase}}
.description{{font-size:17px;line-height:1.55;margin:14px 0 0}}
.requested{{color:#aaa39a;font-size:13px;line-height:1.45;margin:12px 0 0;font-style:italic}}
.foot{{border-top:1px solid #303030;margin-top:24px;padding-top:16px;color:#b9b4ad;font:13px/1.55 Arial,sans-serif}}
.foot strong{{color:#eee}} a{{color:#ddd}}
@media(max-width:680px){{body{{padding:16px 12px 30px}}.grid{{grid-template-columns:1fr}}.portrait{{height:330px}}}}
@media print{{body{{background:#050505;-webkit-print-color-adjust:exact;print-color-adjust:exact}}.card{{break-inside:avoid}}}}
</style></head><body>
<header>
<div class="kicker">Historical reference · Afghanistan War · 2001–2021</div>
<h1>World Leaders & Afghanistan Deployments</h1>
<p class="intro">All 26 leaders in the requested 21 August 2007 reference order. Two-column rounded black portrait boxes, with the requested custom status colours and concise contribution descriptions.</p>
<div class="legend"><span class="status combat">COMBATANT</span><span class="status mid">MID-COMBATANT</span></div>
</header>
<main class="grid">{''.join(card_html)}</main>
<footer class="foot">
<p><strong>Classification note:</strong> “COMBATANT” and “MID-COMBATANT” are custom infographic labels requested for this project, not formal NATO or ISAF legal classifications. National caveats, command arrangements and mission roles varied by country, unit and year. The labels preserve the categories shown in your supplied video; they should not be read as an official NATO classification.</p>
<p><strong>Historical context:</strong> The Congressional Research Service's November 2007 Afghanistan report lists ISAF contributing nations and discusses national caveats on combat operations. It distinguishes forces carrying heavier combat responsibilities from more restricted or reconstruction-focused contributions. NATO's Afghanistan timeline records the 2006 expansion of ISAF and the 2008 strategic vision. <a href="https://www.everycrsreport.com/files/20071101_RL30588_649d832f50e7fbd75d66dc8439c2cc2302b5566d.html">CRS 2007 report</a> · <a href="https://www.nato.int/en/what-we-do/operations-and-missions/nato-and-afghanistan">NATO timeline</a>.</p>
<p><strong>Portrait notes:</strong> Sarkozy — European People's Party, 28 October 2010, CC BY 2.0. Brown — World Economic Forum / Andy Mettler, 25 January 2008, CC BY-SA 2.0. Merkel — Raimond Spekking, 14 June 2019, CC BY-SA 4.0. Prodi — exact photograph supplied by the user. Remaining portrait crops are retained from the user's supplied video capture.</p>
</footer></body></html>"""
out="/mnt/data/afghanistan_leaders_26_box_diagram.html"
Path(out).write_text(page,encoding="utf-8")
print("Created", out, "| cards:", len(cards), "| bytes:", os.path.getsize(out))
2
1
11KB
12KB
193.0ms
368.0ms
201.0ms