"""
GLAMWalk -- Volume 3: Data at Scale
07_iiif_info_to_image_url.py

Converting a IIIF info.json URL (metadata about an image) into a real image-request URL that actually returns pixels.

Source: Volume Three, Section 3.5 -- A Real Vocabulary Word Worth Knowing: IIIF
Targets Python 3.11.4 -- see Volume One, Chapter 1.5/1.6.
"""

def iiif_info_to_image_url(info_url, size="full/!800,800/0/default.jpg"):
    """
    A IIIF info.json URL describes an image; it isn't one. Swap it for
    a real image-request URL using IIIF's own documented URL grammar.
    "!800,800" means: fit within an 800x800 box, preserving aspect ratio.
    """
    if info_url.endswith("/info.json"):
        return info_url.replace("/info.json", f"/{size}")
    return info_url

url = iiif_info_to_image_url(
    "https://some-institution.example/iiif/2/abc123/info.json"
)
print(url)
# https://some-institution.example/iiif/2/abc123/full/!800,800/0/default.jpg
