"""Download the NASA photographs used on the website (all public NASA imagery) into . Usage: python fetch_photos.py (e.g. site_src/img) Sources: NASA GIBS (VIIRS Black Marble 2016) and the NASA Image and Video Library (images-assets.nasa.gov). """ import os import sys import requests from PIL import Image, ImageEnhance out = sys.argv[1] os.makedirs(out, exist_ok=True) GIBS = ("https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi?SERVICE=WMS&REQUEST=GetMap&VERSION=1.1.1" "&SRS=EPSG:4326&FORMAT=image/jpeg&LAYERS=VIIRS_Black_Marble&TIME=2016-01-01" "&BBOX=14.2,41.9,48.2,54.9&WIDTH=2600&HEIGHT=1495") LIB = "https://images-assets.nasa.gov/image/{i}/{i}~large.jpg" # nasa_id -> (file name, max width, optional crop box) PHOTOS = { "iss063e067994": ("iss_beirut_2020-08-11.jpg", 1600, None), "iss008e20656": ("iss_kyiv_2004.jpg", 900, None), "PIA23911": ("aster_smoke_2020.jpg", 1800, (0, 500, 1852, 1310)), "iss071e439719": ("iss_canada_smoke_2024.jpg", 1280, (0, 0, 1280, 1150)), } def get(url, path): r = requests.get(url, timeout=120) r.raise_for_status() with open(path, "wb") as f: f.write(r.content) raw = os.path.join(out, "_raw.jpg") get(GIBS, raw) im = ImageEnhance.Brightness(Image.open(raw).convert("RGB")).enhance(1.15) im.save(os.path.join(out, "hero_blackmarble.jpg"), quality=82, optimize=True, progressive=True) for nasa_id, (name, width, crop) in PHOTOS.items(): get(LIB.format(i=nasa_id), raw) im = Image.open(raw).convert("RGB") if crop: im = im.crop(crop) if im.width > width: im = im.resize((width, round(im.height * width / im.width)), Image.LANCZOS) im.save(os.path.join(out, name), quality=80, optimize=True, progressive=True) print(name, im.size) os.remove(raw)